自动布局指南:带有自定义覆盖的 UIImagePickerController 不会旋转
Auto-Layout Guide: UIImagePickerController W/ Custom Overlay Won't Rotate
我有一个带有自定义叠加层的 UIImagePickerController。在叠加层的 nib 文件中,我为两个不同的大小设置了 UI 约束 classes wc hR
纵向和 wC hC
横向。每个约束都安装了正确的大小 class。
但是,当我转动相机风景时它不会旋转。我这样设置 UIImagePickerController
:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
[[NSBundle mainBundle] loadNibNamed:@"SnapItCameraView" owner:self options:nil];
self.overlayView.frame = ipc.cameraOverlayView.frame;
ipc.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
ipc.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
ipc.cameraViewTransform = CGAffineTransformScale(ipc.cameraViewTransform, scale, scale);
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = YES;
[ipc setAllowsEditing:YES];
}else{
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentViewController:ipc animated:YES completion:nil];
[_activityIndicator stopAnimating];
}
来自 Apple 的文档:
Important
The UIImagePickerController class supports portrait mode only.
参考:https://developer.apple.com/documentation/uikit/uiimagepickercontroller?language=objc
我有一个带有自定义叠加层的 UIImagePickerController。在叠加层的 nib 文件中,我为两个不同的大小设置了 UI 约束 classes wc hR
纵向和 wC hC
横向。每个约束都安装了正确的大小 class。
但是,当我转动相机风景时它不会旋转。我这样设置 UIImagePickerController
:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
[[NSBundle mainBundle] loadNibNamed:@"SnapItCameraView" owner:self options:nil];
self.overlayView.frame = ipc.cameraOverlayView.frame;
ipc.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
ipc.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
ipc.cameraViewTransform = CGAffineTransformScale(ipc.cameraViewTransform, scale, scale);
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = YES;
[ipc setAllowsEditing:YES];
}else{
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentViewController:ipc animated:YES completion:nil];
[_activityIndicator stopAnimating];
}
来自 Apple 的文档:
Important
The UIImagePickerController class supports portrait mode only.
参考:https://developer.apple.com/documentation/uikit/uiimagepickercontroller?language=objc