I'm currently building an iOS app (supporting iOS >= 8) that has initial splash screen animation on start up. This animation blocks the entire screen during 2~3 seconds and then hides itself.
Goal is that the screen orientation should be fixed to portrait mode, and be released when the animation is over. This can be easily achieved by the following code:
- (void)onSplashAnimationEnded {
_isFinished = YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if (_isFinished) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
The problem is that when a user launched the app in landscape mode, and when the animation is finished, the device orientation (currently in landscape mode) does not apply to the app (locked in portrait mode, as intended).
It seems natural that the current orientation of device is automatically applied to the app right after the animation is over. I tried the followings to solve this and none of them works.
- (void)onSplashAnimationEnded {
_isFinished = YES;
// #1
[UIViewController attemptRotationToDeviceOrientation];
// #2
[[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
// #3
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidChangeStatusBarOrientationNotification object:[UIApplication sharedApplication]];
}
I really hope someone to share any workarounds for this issue.
Edit #1
I have read the other question that is linked to mine, and want to add some detail about it.
It is possible to lock or unlock device rotation in a certain situation as described in the link, and I already implemented the feature in other way.
What is left can be regenerated by the following procedure:
- Set iPad in landscape mode.
- Launch the app (which will force the orientation in portrait mode), without rotating the device.
- When the animation is over, the device remains in portrait mode (which is odd because the device is in landscape mode).
- Orientation can be fixed when user tries to rotate to portrait > landscape mode one or twice.
- What I do want to do is to eliminate the step #4.