蘋果已經提出和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