Very intermittent orientation on the device and simulator

I noticed that I find a very intermittent orientation on my device and simulator.

I have a modal view controller that I present, and this is the only thing in my application that supports rotation.

If I started the application in portrait without moving the device, open the trendy VC and then rotate the device, it usually works. However, sometimes, if I open the application that holds the device in the landscape, then I turn to the portrait, start VC, and then turn the device, without turning. It seems very choppy. Sometimes, if I launch the application in portrait mode, and then open the VC and rotate the device, nothing happens, and until I leave and restart it, there will be no orientation in the application.

This is strange because it works 50% of the time! Whenever I run it through Xcode and set breakpoints in shouldAutorotateToInterfaceOrientation, it always works!

Has anyone ever had this or knew what was going on?

+5
source share
5 answers

Because, as you mentioned "intermittent," I would say that this has something to do with what you do after the turn.

To find the error, I suggest deleting any code after the rotation occurs. Comment on any OpenGL network activities or operations. It may also help close Xcode and reopen it.

If all else fails, I would make a new project and start moving files one at a time and testing.

+1
source

, , , UINavigationController, . , :

  • presentModalViewController: , viewController.

  • , shouldAutorotateToInterfaceOrientation: - :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (self.modalViewController) {
        return [self.modalViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
0

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

? (, , , ?)

, , - [UIWindow makeKeyWindow] [UIResponder becomeFirstResponder].

UIDeviceOrientationDidChangeNotification , Modal [UIViewController shouldAutorotateToInterfaceOrientation:] .

0

- , !

, UIView, UIWindow, , . . Default.png, , !

0

, , .

I do not know what code you use for this. The following is an example taken from Apple code snippets. See if that helps.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {    
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        self.view = self.portrait;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
        self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);  
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view = self.landscape;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
        self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
    }
    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        self.view = self.portrait;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
        self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.view = self.landscape;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = 
        CGAffineTransformMakeRotation(degreesToRadian(90));
        self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
    }
}
-1
source

All Articles