IPhone UIActionSheet auto rotation not working

I read a lot about it. People say that he will not autorotate when his parent is not set to rotate automatically. I tried everything but no luck. I created a view-based application (v4.2) with a button that does this:

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

The root controller is set to auto-rotate. There is no ActionSheet. Note that when you rotate the simulator, none of the orientation methods of the root controller are called. Are there any problems with the delegate? What's wrong?

+5
source share
2 answers

Well, here is my solution to this problem:

We mainly do the following:

  • .
  • click.
  • . ( , .

:

@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];
}
+6

, , ( ). , , , .

, , , viewDidAppear, , . , , .

, :

  • , , , .
  • .
  • .
  • viewDidLoad: , .
  • ; .
+1

All Articles