self.prevIEwLayer = [[AVCaptureVIDeoPrevIEwLayer alloc] initWithSession:self.captureSession];self.prevIEwLayer.orIEntation = AVCaptureVIDeoOrIEntationLandscapeRight;[self.displayContainer.layer addSublayer:self.prevIEwLayer];
但是,我意识到AVCaptureVIDeoPrevIEwLayer的orIEntation属性已被弃用,转而支持AVCaptureConnection.vIDeoOrIEntation.当使用它时:
self.prevIEwLayer.connection.vIDeoOrIEntation = AVCaptureVIDeoOrIEntationLandscapeRight;
即使在尝试不同的方向选项时,预览图层也不会改变方向.为了以推荐的方式做到这一点,我还缺少另一个步骤吗?
编辑:
以下是视图控制器中存在的自动旋转方法:
-(BOol)shouldautorotate{ return NO;}-(NSUInteger)supportedInterfaceOrIEntations{ return UIInterfaceOrIEntationMaskLandscapeRight;}-(UIInterfaceOrIEntation)preferredInterfaceOrIEntationForPresentation{ return UIInterfaceOrIEntationLandscapeRight;}
解:
通过应用@ Spectravideo328的答案中的所有建议,以及将预览图层添加到VIEwControllers视图图层而不是displayContainer子视图,可以解决这个问题.
解决方法 您的问题不是AvCaptureVIDeoPrevIEwLayer问题,而是一般的CALayer问题(prevIEwLayer是其子类).所有CALayers都需要设置框架:在您的情况下,我只会添加到您的代码中:
self.prevIEwlayer.frame=self.vIEw.bounds.
使用self.vIEw.bounds而非self.vIEw.frame至关重要,以便在旋转设备时旋转(调整)预览层尺寸.
希望这可以帮助.
更新:
这来自supportedInterfaceOrIEntations帮助说明:
When the user changes the device orIEntation,the system calls this method on the root vIEw controller or the topmost presented vIEw controller that fills the window. If the vIEw controller supports the new orIEntation,the window and vIEw controller are rotated to the new orIEntation. This method is only called if the vIEw controller’s shouldautorotate method returns YES.
更新您的shouldautorotate以始终返回YES.
总结以上是内存溢出为你收集整理的ios6 – 更改AVCaptureVideoPreviewLayer方向的问题全部内容,希望文章能够帮你解决ios6 – 更改AVCaptureVideoPreviewLayer方向的问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)