iPhone UIActionSheet自动旋转不起作用 [英] iPhone UIActionSheet auto-rotating not working
本文介绍了iPhone UIActionSheet自动旋转不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读了很多.人们说,如果其父级未设置为自动旋转,它将不会自动旋转.我尝试了一切,但没有运气. 我创建了一个基于视图的应用程序(v4.2),该按钮执行了以下操作:
I read a lot about that. People say it will not autorotate whene its parent is not set to auto rotate. I tried everything but no luck. I created view-based app (v4.2) with a button that executes this:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Other Button 1", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
根控制器设置为自动旋转. actionSheet没有.请注意,当我旋转模拟器时,不会调用任何根控制器的定向方法.代表有问题吗?怎么了?
The root controller is set to auto-rotate. The actionSheet does not. Note that when I rotate the simulator none of the root controller's orientation methods are called. Is there a problem with the delegate? What is wrong?
推荐答案
好,这是我对这个问题的解决方案:
Well, here's my solution to this problem:
基本上我们要做的是:
- 听旋转事件.
- 收听点击事件.
- 关闭actionSheet并在旋转完成后再次显示. (我们需要等待一小段延迟才能采取.
例如:
@interface ViewController ()
{
UIActionSheet *_sheet;
BOOL _isClicked;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (IBAction)click:(id)sender
{
_isClicked = YES;
[self showActionSheet];
}
- (void)didRotate:(NSNotification *)note
{
[_sheet dismissWithClickedButtonIndex:1 animated:YES];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:1.0];
}
- (void)showActionSheet
{
if (!_isClicked) return;
_sheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"new" otherButtonTitles:@"bla", nil];
[_sheet showInView:self.view];
}
这篇关于iPhone UIActionSheet自动旋转不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文