gpt4 book ai didi

iOS,PopOverPresentationController 问题,.xib

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:29 26 4
gpt4 key购买 nike

我有一个 NavigationController,另一个 Controller 被压入其堆栈:BNRDetailsViewController。现在,在 BNRDetailsViewController 中,我试图在按下工具栏按钮时显示一个弹出窗口,这会向我显示 UIImagePickerController(仅在 iPad 设备上)。因此,我尝试遵循以下 stackoverflow 线程:

UIPopoverPresentationController on iOS 8 iPhone

但是没有成功。如果我只使用他们的代码,我会收到一条错误消息,指出 pushing navigationController is not supported。如果我尝试像这样推送新创建的 UIPopoverPresentationController:[self.navigationController pushViewController:self.imagePickerPopover animated:YES]; 它会崩溃,因为 UIPopoverPresentationController 不是 UIViewController 类型,所以,我想,我不能只是将它压入堆栈。

在这种特殊情况下,您建议做什么?

这是我现在拥有的代码,它在按下工具栏按钮时触发:

- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// If the device have camera, take a picture, otherwise,
// just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

imagePicker.delegate = self;

// Place image picker on the screen
//[self presentViewController:imagePicker animated:YES completion:NULL];

// Place image picker on the screen
// Check for iPad device before instantiating the popover controller
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Create a new popover controller that will display the imagePicker
_imagePickerPopover = [[UIPopoverPresentationController alloc] initWithPresentedViewController:imagePicker presentingViewController:self];

imagePicker.preferredContentSize = CGSizeMake(280, 200);
_imagePickerPopover.delegate = self;
_imagePickerPopover.sourceView = self.view;
CGRect frame = [[sender valueForKey:@"view"] frame];
frame.origin.y = frame.origin.y + 20;
_imagePickerPopover.sourceRect = frame;
// [self.navigationController pushViewController:self.imagePickerPopover animated:YES];
}
}

最佳答案

这是基于您的代码的代码,它将使弹出窗口显示在 iPad 上。

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
imagePicker.modalPresentationStyle = UIModalPresentationPopover;
imagePicker.preferredContentSize = CGSizeMake(280, 200);
CGRect frame = [[sender valueForKey:@"view"] frame];
frame.origin.y = frame.origin.y + 20;

UIPopoverPresentationController *popoverController =
imagePicker.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = frame;

[self.navigationController presentViewController:imagePicker
animated:YES completion:nil];
}

关于iOS,PopOverPresentationController 问题,.xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713482/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com