我正试图在ipad横向模式下显示我的UIImagePicker ..
我遵循了这个例子:https://github.com/guillermomuntaner/GMImagePicker
但我收到以下错误:
<UIView: 0x7f8c9d158800; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x7f8c9d14f090>>'s window is not equal to <LoginRegisterViewController: 0x7f8c9ac51a70>'s view's window!
我的代码是:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = picker.popoverPresentationController;
popPC.permittedArrowDirections = UIPopoverArrowDirectionDown;
popPC.sourceView = btnImagemPerfil;
popPC.sourceRect = btnImagemPerfil.bounds;
NSLog(@"%@", NSStringFromCGRect(btnImagemPerfil.bounds));
[self showViewController:picker sender:sender];
和来自btnImagemPerfil.bounds的日志
{{0, 0}, {141, 141}}
答案 0 :(得分:2)
将我的代码更新为:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.window.rootViewController = self;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = picker.popoverPresentationController;
popPC.permittedArrowDirections = UIPopoverArrowDirectionDown;
popPC.sourceView = btnImagemPerfil;
popPC.sourceRect = btnImagemPerfil.bounds;
NSLog(@"%@", NSStringFromCGRect(btnImagemPerfil.bounds));
[self showViewController:picker sender:sender];
它对我有用