UIModalViewController 和 UIImagePickerController 旋转问题

发布于 2025-01-03 06:22:03 字数 1334 浏览 0 评论 0原文

情况是这样的: 我有一个以这种方式呈现的 viewController:

AddAttachmentPhotoVideoViewController * addAttachment = [[AddAttachmentPhotoVideoViewController alloc]initWithNibName:nil bundle:nil attachmentType:AtImage];
addAttachment.modalPresentationStyle = UIModalPresentationFormSheet;
addAttachment.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            
[self presentModalViewController:addAttachment animated:YES];

addAttachment 中,有一个以这种方式打开相机的按钮:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;    
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
imagePicker.showsCameraControls = YES;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
imagePicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:imagePicker animated:YES];

问题如下:当我旋转设备 (iPad) 时,>imagePicker 会自行旋转,但 addAttachment 不会旋转;因此,当我关闭选择器时,addAttachment 的框架错误,并且无法正确旋转。

换句话说,当显示相机时,其下方的模态视图控制器不会接收旋转,因此,当我关闭选择器时,视图控制器的框架完全错误。

谢谢...

This is the situation:
I've a viewController that was presented in this way:

AddAttachmentPhotoVideoViewController * addAttachment = [[AddAttachmentPhotoVideoViewController alloc]initWithNibName:nil bundle:nil attachmentType:AtImage];
addAttachment.modalPresentationStyle = UIModalPresentationFormSheet;
addAttachment.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            
[self presentModalViewController:addAttachment animated:YES];

in addAttachment there is a button that open the camera in this way:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;    
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
imagePicker.showsCameraControls = YES;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
imagePicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:imagePicker animated:YES];

The issue is the following: when I rotate the device (iPad) the imagePicker rotates itself but the addAttachment doesn't rotate; so when I dismiss the picker the addAttachment has a wrong frame and it's not rotate properly.

In other words, when the camera is shown, the modal view controller under it, doesn't receive the rotation and so, when I dismiss the picker, the frame of view controller is totally wrong.

Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人如玉 2025-01-10 06:22:03

您必须手动处理 ViewController 的旋转。

前台 ViewController 应该将旋转消息传播到其后面的所有 ViewController。

You must handle the rotation of your ViewController manually.

The foreground ViewController should propagate the rotation message to all ViewControllers behind of it.

晨光如昨 2025-01-10 06:22:03

您必须告诉 AddAttachmentPhotoVideoViewController 它应该自动旋转到所有界面方向。默认情况下,仅针对纵向返回 YES。添加以下方法以允许自动旋转到所有方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

You have to tell the AddAttachmentPhotoVideoViewController that it should auto-rotate to all interface orientations. By default, YES is only returned for portrait orientation. Add the following method to allow auto-rotation to all orientations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文