无法集中UIPopoverController

时间:2016-01-05 11:31:43

标签: ios ipad uipopovercontroller

在我的应用中,我试图将UIPopoverController集中在一起(因为我的应用程序与iOS 7兼容,我才能使用它)。我试图将其置于中心但没有成功。我的代码以中心为中心:

        SummaryViewController *summaryViewController = [[SummaryViewController alloc] init];
        summaryViewController.delegate = self;
        aPopover = [[UIPopoverController alloc] initWithContentViewController:summaryViewController];
        aPopover.popoverContentSize = CGSizeMake(summaryViewController.view.frame.size.width, summaryViewController.view.frame.size.height);

        CGFloat width = [[UIScreen mainScreen] bounds].size.width;
        CGFloat height = [[UIScreen mainScreen] bounds].size.height;
        CGFloat popoverWidth = summaryViewController.view.frame.size.width;
        CGFloat popoverHeight = summaryViewController.view.frame.size.height;

        CGRect rect = CGRectMake((width - popoverWidth) / 2.0, (height -popoverHeight) / 2.0, 1, 1);
        [aPopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];

它总是向我展示左下角的弹出窗口...... 这段代码有什么问题?

1 个答案:

答案 0 :(得分:1)

  SummaryViewController *summaryViewController = [[SummaryViewController alloc] init];
  summaryViewController.delegate = self;
  aPopover = [[UIPopoverController alloc] initWithContentViewController:summaryViewController];
  aPopover.popoverContentSize = CGSizeMake(summaryViewController.view.frame.size.width, summaryViewController.view.frame.size.height);

  CGFloat width = [[UIScreen mainScreen] bounds].size.width;
  CGFloat height = [[UIScreen mainScreen] bounds].size.height;
  CGFloat popoverWidth = summaryViewController.view.frame.size.width;
  CGFloat popoverHeight = summaryViewController.view.frame.size.height;

  CGRect rect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, 1, 1);
  [aPopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];