首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在actionSheet 8中做"actionSheet showFromRect“?

如何在actionSheet 8中做"actionSheet showFromRect“?
EN

Stack Overflow用户
提问于 2014-08-07 03:34:55
回答 4查看 3.6K关注 0票数 4

在iOS 7中,我用“showFromRect”来显示actionSheet:

代码语言:javascript
复制
[actionSheet showFromRect:rect inView:view animated:YES];

但在iOS 8中,这是行不通的。它们取代了实现,并建议我们使用UIAlertController。那么,我如何将这个actionSheet显示为一个弹出器呢?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-11-17 10:28:52

使用UIAlertController,您可以访问popoverPresentationController属性来设置sourceView (又名inView)和sourceRect (又名fromRect)。这提供了与前面的showFromRect:inView相同的外观:

代码语言:javascript
复制
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];
票数 12
EN

Stack Overflow用户

发布于 2014-10-14 04:37:15

我也像您一样遇到了这个问题,但我的情况是,我在UIActionSheet设备上显示了UIWindow.view中的一个UIWindow,而UIWindow没有设置rootViewController

因此,我发现,如果我们在一个rootViewController等于nil的窗口中显示一个UIActionSheet,那么UIActionSheet就不能显示出来。

我的解决办法是

代码语言:javascript
复制
window.rootViewController = [[UIViewController alloc] init];

然后,

代码语言:javascript
复制
[actionSheet showFromRect:rect inView:window.rootViewController.view animated:YES].

希望这能帮到你!

票数 3
EN

Stack Overflow用户

发布于 2014-08-07 04:38:50

我发现关键是在iOS 7中,在使用"showFromRect: inView:"时,您在新窗口中实际显示了actionSheet

但是在iOS 8中,您只在发送参数的视图上显示actionSheet

所以解决办法是

代码语言:javascript
复制
self.superView
    [actionSheet showFromRect:rect inView:[self.superView] animated:YES];

我和我的同事通过随机的尝试找出了答案。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25173682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档