我目前正在使用iPad版本的应用程序,在该版本中,我使用UIImagePickerController让用户从他们的照片库中选择照片。
在iPad中,一条错误消息提示您使用了弹出框,但我无法在全屏模式下显示图像选择器。有可能吗?
有人告诉我可以使用presentModalViewController完成。如果是这样,谁能指出我的教程?
有可能!
只需删除此:
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popoverController presentPopoverFromRect:frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
并改用它:
[self presentModalViewController:picker animated:YES];
选择器是您的UIImagePickerController。
不可能。仅弹出窗口可用于执行此操作,无法全屏显示。
Swift:可以通过更改modalPresentationStyle
。
@IBAction func openPhotoLibrary(_sender:UIButton){
if !UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){return}
let imagePicker = UIImagePickerController()
imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
imagePicker.allowsEditing = false
imagePicker.delegate = self
imagePicker.modalPresentationStyle = .overCurrentContext
self.present(imagePicker, animated: true, completion: nil)
}