Fix Notification center orientation after the app resume execution

主宰稳场 提交于 2020-01-13 05:36:06

问题


I have a view that is made to be displayed in landscape mode only, and is working well. But if you send the app to the background and then resume it, the notification center will appear in the orientation you had the device when resuming the app (usually portrait mode), so when I detect a swipe from left to right sometimes the notification center will appear. Any ideas how I can make the system know that it should show the notification center in landscape mode?

EDIT: The view displays in landscape mode as it should, the problem is only with the notification center.


回答1:


Setting the status bar orientation sets the apps orientation. Alerts, NotificationCenter they all use the [UIApplication sharedApplication].statusbarOrientation as the orientation.

-(BOOL)shouldAutorotateToInterfaceOrientation should do it all for you but if, as you are saying, it isn't then you can set the orientation yourself.




回答2:


You can programmatically stop a portrait mode coming into play in the shouldAutorotateToInterfaceOrientation method, the following code is how you do that:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        return YES;
    }
    else {
        return NO;
    }

}


来源:https://stackoverflow.com/questions/11314314/fix-notification-center-orientation-after-the-app-resume-execution

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