iOS 7:在 UIActionSheet 委托函数中创建的 UIAlertView 无法自动旋转

Posted

技术标签:

【中文标题】iOS 7:在 UIActionSheet 委托函数中创建的 UIAlertView 无法自动旋转【英文标题】:iOS 7: UIAlertView created in UIActionSheet delegate function cannot auto rotate 【发布时间】:2013-10-21 09:43:41 【问题描述】:

这个问题只能在 ios 7 中重现。

在delegate函数中:- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex,如果创建了UIAlertView,则alert view不能自动旋转。下面是示例代码:

- (IBAction)buttonTapped:(id)sender

    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"action sheet"
                                  delegate:self
                                  cancelButtonTitle:@"cancel"
                                  destructiveButtonTitle:@"ok"
                                  otherButtonTitles:nil];
    [actionSheet showInView:self.view];


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"alert"
                          message:nil
                          delegate:self
                          cancelButtonTitle:@"ok"
                          otherButtonTitles:nil];
    [alert show];

这是 iOS 7 的错误吗?如果是,有没有办法让警报视图与屏幕中的其他视图一起自动旋转?

【问题讨论】:

【参考方案1】:

尝试从 UIActionSheet 的另一个委托方法呈现警报视图。这确实有效:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex

这肯定看起来像 iOS7 中的一个错误 :)

【讨论】:

以上是关于iOS 7:在 UIActionSheet 委托函数中创建的 UIAlertView 无法自动旋转的主要内容,如果未能解决你的问题,请参考以下文章