Can a viewcontroller presented modally over curren

2019-05-30 03:41发布

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条回答
Explosion°爆炸
2楼-- · 2019-05-30 04:20

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.

查看更多
登录 后发表回答