Stop Device orientation

2019-08-02 03:50发布

While running my app I get errors which indicate that rotation notifications are being sent and crashing the app. Is there a way I can stop all rotation events from being sent to see if I can stop the crashes. Also is there a good overview of how these events should be handled. Do I have to handle them separately in in controllers or in all views. For the moment I would be quite happy to lock in portrait.

I have tried calling [[UIDevice currentDevice] endGenerating Device OrientationNotifications]; but I am still getting device Orientation DidChange events unrecognized selector sent to instance

1条回答
迷人小祖宗
2楼-- · 2019-08-02 03:57

You can't stop rotation notifications, nor should you try to.

The notifications aren't causing your crash, you must have some bad code in there.

Paste your exact error from the console and the code for the view controller where it's happening. My guess is that you've written a rotation handler method that doesn't work, possibly without realising it.

You can lock in portrait by creating a view controller base class that has this method, then using it as the superclass for all your other view controllers:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
查看更多
登录 后发表回答