在iOS 7中,我用“showFromRect”来显示actionSheet:
[actionSheet showFromRect:rect inView:view animated:YES];但在iOS 8中,这是行不通的。它们取代了实现,并建议我们使用UIAlertController。那么,我如何将这个actionSheet显示为一个弹出器呢?
发布于 2014-11-17 10:28:52
使用UIAlertController,您可以访问popoverPresentationController属性来设置sourceView (又名inView)和sourceRect (又名fromRect)。这提供了与前面的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];发布于 2014-10-14 04:37:15
我也像您一样遇到了这个问题,但我的情况是,我在UIActionSheet设备上显示了UIWindow.view中的一个UIWindow,而UIWindow没有设置rootViewController。
因此,我发现,如果我们在一个rootViewController等于nil的窗口中显示一个UIActionSheet,那么UIActionSheet就不能显示出来。
我的解决办法是
window.rootViewController = [[UIViewController alloc] init];然后,
[actionSheet showFromRect:rect inView:window.rootViewController.view animated:YES].希望这能帮到你!
发布于 2014-08-07 04:38:50
我发现关键是在iOS 7中,在使用"showFromRect: inView:"时,您在新窗口中实际显示了actionSheet;
但是在iOS 8中,您只在发送参数的视图上显示actionSheet。
所以解决办法是
self.superView
[actionSheet showFromRect:rect inView:[self.superView] animated:YES];我和我的同事通过随机的尝试找出了答案。
https://stackoverflow.com/questions/25173682
复制相似问题