【发布时间】:2016-03-20 18:45:16
【问题描述】:
我在 UIViewController 中有一个 UIView,UIView 用于使用 AVCaptureSession 捕获照片。
因此我不希望我的 UIView 在我的设备旋转时旋转,为了实现这一点,我编写了这段代码。
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGAffineTransform deltaTransform = coordinator.targetTransform;
CGFloat deltaAngle = atan2f(deltaTransform.b, deltaTransform.a);
CGFloat currentRotation = [[self.camera.layer valueForKeyPath:@"transform.rotation.z"] floatValue];
currentRotation += -1 * deltaAngle + 0.0001;
[self.camera.layer setValue:@(currentRotation) forKeyPath:@"transform.rotation.z"];
}
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGAffineTransform currentTransform = self.camera.transform;
currentTransform.a = round(currentTransform.a);
currentTransform.b = round(currentTransform.b);
currentTransform.c = round(currentTransform.c);
currentTransform.d = round(currentTransform.d);
}];
}
在纵向模式下,当我旋转时,我的 UIView 打开全屏旋转对我的相机 UIView 和其他 UIView 旋转没有任何影响,但问题是在旋转到横向模式时,我的相机 UIView 不是全屏并且在屏幕上随机显示大小,我做错了什么?
注意:我使用情节提要设计了视图
【问题讨论】:
-
您是否尝试禁用自动布局?
-
我无法禁用自动布局我希望我的其他 UIView 具有捕获按钮和闪光灯按钮正确旋转
标签: ios objective-c uiview uiviewcontroller