Can a viewcontroller presented modally over current context (UIModalPresentationStyleOverCurrentContext) be rotated with device?

此生再无相见时 提交于 2019-12-23 01:19:13

问题


I have a controller which should be rotated with interface (device) orientation change. I track orientation changes, however i'm unable to rotate the view with the device orintation changes.

I can animate the views inside, and switch their constraints etc, but i'd like to use Size classes for that. When i switch to UIModalPresentationStyleCurrentContext on presenting the controller it works, but messes with my navigation and tabbar, and i would like to do it this way.

Can it be done this way?


回答1:


Ok, solved it.

I track device orientation changes by putting this in viewDidLoad of the controller which needs to change orientation:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                       selector:@selector(orientationChanged:)
                                             name:@"UIDeviceOrientationDidChangeNotification"
                                           object:nil];

Then in orientationChanged:

- (void)orientationChanged:(NSNotification *)notification{
    [RecorderViewController attemptRotationToDeviceOrientation];
}

In order for that to work in the parent controller i added these :

-(BOOL) shouldAutorotate {
    return true;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

Also, for rotation to work recorder controller has to implement these:

- (BOOL)shouldAutorotate {
    return true;
}




- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
} 

Hopefully somebody finds this useful.



来源:https://stackoverflow.com/questions/31700372/can-a-viewcontroller-presented-modally-over-current-context-uimodalpresentation

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