iPhone UIActionSheet 自动旋转不起作用

标签 iphone orientation rotation uiactionsheet autorotate

我读了很多相关内容。人们说,当其父级未设置为自动旋转时,它不会自动旋转。我尝试了一切但没有运气。 我创建了基于 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 的任何方向方法。代表有问题吗?怎么了?

最佳答案

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

基本上我们所做的是:

  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];
}

关于iPhone UIActionSheet 自动旋转不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4859352/

相关文章:

IOS Phonegap 3.X : Lock page orientation during runtime

iphone - 方向改变后UIView addsubview : Tell view to resize

SVG绕中心旋转是移动物体

iphone - 在 iphone 中选择应用内购买项目的困惑

iphone - 通过触摸平滑旋转 UIView

ios - 在 iPad 中以横向模式启动 iPhone App

Java AffinetransformOp filter() 搞砸了我的形象

css - 使用 CSS 旋转鼠标光标图标

iphone - iPhone 应用程序存储数据的最佳实践

iphone - 选择单元格时如何设置 accessoryType