问题
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