【问题标题】:Popover presentation on an iPhone using UIPopoverPresentationController使用 UIPopoverPresentationController 在 iPhone 上的 Popover 演示
【发布时间】:2017-05-13 02:01:42
【问题描述】:

大家好,我想为 iPhone 制作一个弹出框,所以这是我出错的代码,请建议我想创建如下图所示的内容,但我的内容覆盖了整个屏幕,我不想使用 segue。所以基本上我想如果我点击按钮,一个调整大小的视图控制器应该弹出我怎么能做到这一点,请帮助。我已经按照本教程进行操作。 https://www.youtube.com/watch?v=UQBbJQNEDA4

#import "ViewController.h"
#import "Popup.h"

@interface ViewController ()<UIPopoverPresentationControllerDelegate>
{
    Popup * popupController;
    UIPopoverPresentationController *popupPresentationController;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)popupOnClick:(id)sender {

    popupController=[self.storyboard instantiateViewControllerWithIdentifier:@"Popup"];
    popupController.modalPresentationStyle=UIModalPresentationPopover;
    popupPresentationController= [popupController popoverPresentationController];
    popupPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
    popupController.preferredContentSize=CGSizeMake(150, 300);
    popupPresentationController.delegate = self;

    [self presentViewController:popupController animated:YES completion:NULL];


    // in case we don't have a bar button as reference
    popupPresentationController.sourceView = _popupButton;
    popupPresentationController.sourceRect = _popupButton.frame;
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
    return UIModalPresentationNone;
}

@end

【问题讨论】:

  • 也尝试实现adaptivePresentationStyleForPresentationController:traitCollection:
  • @LeoNatan 先生,您能帮我编辑一下代码吗?
  • 没有。阅读文档并在您的代码中实现它。
  • @LeoNatan 可以为任何可以提供建议的机构工作
  • 我知道它确实有效,因为我在 iPhone 上使用过它。

标签: ios objective-c uipopovercontroller popover


【解决方案1】:

这是你的问题:

[self presentViewController:popupController animated:YES completion:nil];
popupPresentationController= [popupController popoverPresentationController];
popupPresentationController.delegate = self;

该代码的顺序错误。您必须设置delegate调用presentViewController

【讨论】:

  • 感谢您的帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多