怎么办“actionSheet showFromRect”在iOS 8中? [英] How to do "actionSheet showFromRect" in iOS 8?
问题描述
在iOS 7中,我通过showFromRect显示actionSheet:
In iOS 7, I show actionSheet by "showFromRect":
[actionSheet showFromRect:rect inView:view animated:YES];
但在iOS 8中,这不起作用。他们替换实现并建议我们使用UIAlertController。然后我如何像弹出窗口一样显示这个actionSheet?
But in iOS 8, this doesn't work. They they replace the implementation and suggest us using UIAlertController. Then how do I show this actionSheet like a popover?
推荐答案
使用UIAlertController你可以访问popoverPresentationController属性来设置sourceView(aka inView)和sourceRect(又名fromRect)。这给出了与之前的showFromRect相同的外观:inView:
Using UIAlertController you can access the popoverPresentationController property to set the sourceView (aka inView) and sourceRect (aka fromRect). This gives the same appearance as the previous showFromRect:inView:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];
// Set the sourceView.
alert.popoverPresentationController.sourceView = self.mySubView;
// Set the sourceRect.
alert.popoverPresentationController.sourceRect = CGRectMake(50, 50, 10, 10);
// Create and add an Action.
UIAlertAction *anAction = [UIAlertAction actionWithTitle:@"Action Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
NSLog(@"Action Pressed");
}];
[alert addAction:anAction];
// Show the Alert.
[self presentViewController:alert animated:YES completion:nil];
这篇关于怎么办“actionSheet showFromRect”在iOS 8中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!