preferredContentSize不适用于iPhone应用程序

时间:2016-10-07 14:02:35

标签: ios objective-c iphone popover

据我所知,popovers适用于iPad,但我正试图在iPhone应用程序中实现一个。

我需要在主视图控制器PopoverVC中显示popover(具有特定大小)视图控制器HomeVC

以下是我在HomeVC中调用popover的方式:

- (IBAction)optionsAction:(UIBarButtonItem *)sender {
    CBOptionsPopoverViewController *optionsViewController = [[CBOptionsPopoverViewController alloc] initWithNibName:CBOptionsPopoverNibIdentifier bundle:nil];
    optionsViewController.delegate = self;
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    optionsViewController.preferredContentSize = CGSizeMake(width, 100.0);
    self.optionsPopover.popoverContentSize = CGSizeMake(width, 100);
    [self presentViewController:optionsViewController animated:YES completion:nil];
}

以下是我在PopoverVC课程中所做的事情:

- (instancetype)init {
    if (self = [super init]) {
        self.modalPresentationStyle = UIModalPresentationPopover;
        self.popoverPresentationController.delegate = self;
    }
    return self;
}

- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationPopover; //You have to specify this particular value in order to make it work on iPhone.
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    self.preferredContentSize = CGSizeMake(width, 100.0);
}

问题是它覆盖了我的整个屏幕,但我只需要一定的尺寸。 可能是因为我正在为iPhone做这个应用程序的问题?或adaptivePresentationStyleForPresentationController我返回UIModalPresentationPopover?

修改 我还补充说:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog(@"yes");
        self.modalPresentationStyle = UIModalPresentationPopover;
        self.popoverPresentationController.delegate = self;
    }
    return self; 
}

但没有帮助。 根据评论。我使用了调试器,并调用了PopoverVC中的所有4个函数。

此外,当我调试并执行“po self.preferredContentSize”时,它显示大小为320x100。即使它是全屏(用户看不到之前的页面)。这意味着它只是不听preferredContentSize

0 个答案:

没有答案