我使用 AVFoundation 框架来访问相机。在标准相机应用程序中,当方向改变时,仅按钮上的图标旋转。但是当我尝试做类似的事情时,我遇到了与方向更改动画相关的问题。预览视图已旋转,其后面的区域为黑色,并且在转动时出现图像抖动。
现在我有这个代码:
-(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];
}
我的想法是使用变换动画来处理旋转动画,但我遇到了 glithes 的问题。
如何创建相机预览视图并解决方向更改问题?可能我必须使用其他仪器来使用相机吗?不是 AVFoundation 框架?
我知道我可以锁定方向并使用加速度计来处理按钮图标。但是我遇到了一些子视图控制器的问题。
对不起糟糕的英语。