苹果已经提出和iOS8上这里配置popovers官方途径希望:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/index.html
虽然类似@ MidhunMP的答案,这是值得一提的段落:
配置酥料饼的演示控制器调用 presentViewController:animated:completion:
可能会看到后, m 违反直觉,但直到您启动演示文稿之后,UIKit才会创建演示文稿控制器 。此外,UIKit必须等待 ,直到下一个更新周期才能在屏幕上显示新内容。 延迟时间让您有时间为您的弹出窗口配置演示控制器 。
如果您想要(https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationControllerDelegate_protocol/index.html),配置和响应事件也可以通过委托完成。
一个例子,撇开使用委托的:
// Present the controller using the popover style.
controller.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:controller animated:YES completion:nil];
// Popover presentation controller was created when presenting; now configure it.
UIPopoverPresentationController *presentationController =
[controller popoverPresentationController];
presentationController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
presentationController.sourceView = containerFrameOfReferenceView;
// arrow points out of the rect specified here
presentationController.sourceRect = childOfContainerView.frame;
但你也想放弃。要做到这一点,而无需使用委托,您呈现控制器可以叫:
[self dismissViewControllerAnimated:YES completion:nil];
但如果我转动我的设备,并且酥料饼不指向正确的区域?您的提供控制器可以处理它:
// Respond to rotations or split screen changes
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:nil
completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
// Fix up popover placement if necessary, after the transition.
if (self.presentedViewController) {
UIPopoverPresentationController *presentationController =
[self.presentedViewController popoverPresentationController];
presentationController.sourceView = containerFrameOfReferenceView;
presentationController.sourceRect = childOfContainerView.frame;
}
}];
}
来源
2016-07-21 02:50:50
qix
如果我知道如何删除警告,那么我没有问过问这个问题。而且当你也不知道如何删除警告时,你评论道。 –
UIStorybaordPopoverSegue.h中的弃用警告已得到改进,现在提供了方向:“从您的segue的performHandler中访问destinationViewController.popoverPresentationController ...” – Mark