iPhone UIActionSheet自动旋转无法正常工作

xpe*_*int 5 iphone rotation orientation uiactionsheet autorotate

我读了很多关于这一点.人们说它不会自动旋转它的父母没有设置为自动旋转.我尝试了一切,但没有运气.我用一个执行此操作的按钮创建了基于视图的应用程序(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];
Run Code Online (Sandbox Code Playgroud)

根控制器设置为自动旋转.actionSheet没有.请注意,当我旋转模拟器时,不会调用根控制器的方向方法.代表有问题吗?怎么了?

Lir*_*rik 6

好吧,这是我解决这个问题的方法:

基本上我们做的是:

  1. 听取旋转事件.
  2. 听取点击事件.
  3. 在旋转完成后,关闭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];
}
Run Code Online (Sandbox Code Playgroud)