Stop Device orientation

ⅰ亾dé卋堺 提交于 2019-12-11 07:34:20

问题


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:


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


来源:https://stackoverflow.com/questions/9239258/stop-device-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!