我使用 AVFoundation 框架来访问相机。 在标准相机应用程序中,当方向发生变化时,只会旋转按钮上的图标。 但是当我尝试做类似的事情时,我遇到了与方向变化动画相关的问题。预览 View 被旋转,它后面的区域是黑色的,并且在旋转时有图像抖动。
现在我有了这段代码:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration]
forKey:kCATransactionAnimationDuration];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureManager.previewLayer.transform=CATransform3DMakeRotation(0, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI+M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
}
我的想法是使用变换动画来处理旋转动画,但我遇到了滑动问题。
如何创建相机预览 View 并解决方向变化问题? 可能我必须使用其他仪器才能使用相机吗?不是 AVFoundation 框架?
我知道我可以锁定方向并使用加速度计来处理按钮图标。但是我遇到了一些 subview Controller 的问题。
抱歉英语不好。
最佳答案
您需要为您的 Controller 禁用横向并通过处理方向更改通知更新图标布局等。在本主题中描述正确 - How to handle autorotation in AVCaptureVideoPreviewLayer?
关于iphone - 如何像 iPhone 上的标准相机应用程序一样处理方向的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14448192/