怎么办“actionSheet showFromRect”在iOS 8中? [英] How to do "actionSheet showFromRect" in iOS 8?

查看:191
本文介绍了怎么办“actionSheet showFromRect”在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆