• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iOS,PopOverPresentationController 问题,.xib

[复制链接]
菜鸟教程小白 发表于 2022-12-12 17:09:25 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

UIPopoverPresentationController on iOS 8 iPhone

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

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

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

- (IBAction)takePictureid)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];
}
}



Best Answer-推荐答案


这是基于您的代码的代码,它将使弹出框显示在 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap