5

我读了很多关于那个。人们说当它的父级没有设置为自动旋转时它不会自动旋转。我尝试了一切,但没有运气。我使用执行此操作的按钮创建了基于视图的应用程序(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 没有。请注意,当我旋转模拟器时,不会调用任何根控制器的方向方法。代表有问题吗?怎么了?

4

2 回答 2

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];
}
于 2012-12-27T12:04:53.337 回答
1

我发现当我在从属视图(我使用导航控制器推送)的委托方法中呈现操作表时遇到了这个问题。问题是我的视图不是当前视图,从属视图仍在我试图显示操作表的位置。

通过稍微更改我的代码,以便委托方法记录与用户所需的交互,并将操作表呈现推迟到该视图的 viewDidAppear 方法,工作表在逻辑界面动画中的适当时间出现,并且自动旋转问题消失了。您可能想看看这是否对您有帮助。

换句话说,流程变成了:

  • 从属视图调用委托方法来报告用户在离开时所做的选择。
  • 父视图记录了这些信息以备后用。
  • 导航控制器被告知弹出从属视图。
  • 父视图的 viewDidLoad: 方法检测到委托方法中的注释。
  • 提交了行动表;旋转现在是正确的。
于 2013-02-16T00:16:45.800 回答