我正在尝试通过UIPopOver更改UI
ImagePicker的大小.代码如下所示.问题是PopOver大小无法正常显示 – 它会以正确的大小短暂闪烁,然后动画缩小到通常的默认大小.
任何人都可以告诉我如何改变弹出窗口的大小?
- (void)showImagePickerForPhotoLibrary { NSLog(@"Picker"); imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePickerController.contentSizeForViewInPopover = CGSizeMake(768,1000); if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Class cls = NSClassFromString(@"UIPopoverController"); if (cls != nil) { popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController]; //popoverController.popoverContentSize = CGSizeMake(768,1000); [popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES]; } } else { [app.mainViewController presentModalViewController:imagePickerController animated:YES]; } }
解决方法
我不确定这是最优雅的解决方案,但它似乎对我来说很好:
您可以将UIImagePickerController的视图嵌入到“容器”UIViewController的视图中.
- (void)showImagePickerForPhotoLibrary { NSLog(@"Picker"); imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; UIViewController *containerController = [[UIViewController alloc] init]; containerController.contentSizeForViewInPopover = CGSizeMake(768,1000); [containerController.view addSubview:imagePickerController.view]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Class cls = NSClassFromString(@"UIPopoverController"); if (cls != nil) { popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController]; [popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES]; [imagePickerController.view setFrame:containerController.view.frame]; } } else { [app.mainViewController presentModalViewController:containerController animated:YES]; } }
希望这可以帮助
编辑:由于一些奇怪的原因,框架确实在景观正确时改变.
为了解决这个问题,您需要在显示弹出窗口后设置图像选择器的视图框架.
我已经编辑了上面的代码来展示这个.
此外,在您的控制器中,添加以下内容:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [imagePickerController.view setFrame:imagePickerController.view.superview.frame]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。