我尝试了几种不同的方法,在一个仅限风景的应用程序(不是我选择的)中呈现面向风景的UIImagePickerController我正在研究。
当我(成功地)以横向格式呈现画廊并滚动图像时,有一个真正可怕的口吃!
我目前使用的技术是:
- (void)presentImagePickerController:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if (isDeviceIPad) {
picker.modalPresentationStyle = UIModalPresentationFormSheet;
picker.preferredContentSize = [UIScreen mainScreen].bounds.size;
}
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker
animated:YES
completion:nil];
}
我无法使用使用私有接口的解决方案,因为该应用必须通过App Store审核。我不想使用第三方图书馆,因为我的老板反对这个想法。
我的iPad是第三代型号MD334LL / A,运行iOS 8.1。
答案 0 :(得分:0)
从这里找到的UIImagePickerController类引用:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class/index.html
在iPad上,呈现图像选择器的正确方法取决于其源类型,如下表所示:
相机:全屏使用
照片库:必须使用popover
保存的相册:必须使用popover
答案:由于我想要展示已保存的相册,我需要使用一个弹出窗口来呈现选择器。
- (void)presentImagePickerController:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = YES;
if (isDeviceIPad() && sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = picker.popoverPresentationController;
presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
presentationController.sourceView = self.presentPickerButton;
presentationController.sourceRect = self.presentPickerButton.bounds;
}
[self presentViewController:picker
animated:YES
completion:nil];
}