Prevent AlertView from auto rotating

后端 未结 3 381
长情又很酷
长情又很酷 2021-01-20 05:38

The launch page of my app is set to portrait only with this little bit of code:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfac         


        
相关标签:
3条回答
  • 2021-01-20 05:56

    Have you try with implementing shouldAutorotate ? You can do in your case :

    - (BOOL)shouldAutorotate
    {
        if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) return NO;
        else return YES;
    }
    
    0 讨论(0)
  • 2021-01-20 06:00

    Try doing this in viewDidAppear:. I've seen weird behavior like this before because view layouts are not entirely defined yet. In viewDidAppear:, everything is set and laid out, so there shouldn't be any problems at that point.

    0 讨论(0)
  • 2021-01-20 06:16

    I was experiencing this, but the alert was being shown from the AppDelegate. After reading Scott Berrevoet's answer about view layouts not being entirely defined yet I added a very slight delay before showing the alert dialog to give everything some time to set up and that fixed the problem.

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) {
        [self.updateAlert show];
    });
    
    0 讨论(0)
提交回复
热议问题