我读了很多相关内容。人们说,当其父级未设置为自动旋转时,它不会自动旋转。我尝试了一切但没有运气。 我创建了基于 View 的应用程序(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];
根 Controller 设置为自动轮换。而actionSheet则没有。请注意,当我旋转模拟器时,不会调用根 Controller 的任何方向方法。代表有问题吗?怎么了?
最佳答案
好吧,这是我解决这个问题的方法:
基本上我们所做的是:
- 监听旋转事件。
- 监听点击事件。
- 关闭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 自动旋转不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4859352/