我读了很多相关内容。人们说,当其父级未设置为自动旋转时,它不会自动旋转。我尝试了一切但没有运气。
我创建了基于视图的应用程序(v4.2),并带有一个执行此操作的按钮:
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则没有。请注意,当我旋转模拟器时,不会调用根控制器的任何方向方法。代表有问题吗?怎么了?
好吧,这是我对这个问题的解决方案:
基本上我们所做的是:
- 监听旋转事件。
- 监听点击事件。
- 关闭 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];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)