简体   繁体   中英

iOS 8 and UIScreen sizing issues

Our app consists of Cocos3D and AR. Since upgrading to iOS 8 we had to fix our orientation handling because of the changes Apple brought on us.

However, we still experience some issues that lead me to a rather interesting phenomena (I checked it in our app and in a fresh new project..):

Logging the [UIDevice currentDevice].orientation , [UIApplication sharedApplication].statusBarOrientation and [UIScreen mainScreen].bounds.size shows that when the device is rotated quickly, the device orientation actually changes, however the interface orientation sometimes stays the same and it leads to wrong calculations of the screen bounds... eg:

before rotation:

[UIDevice currentDevice].orientation = 1

[UIApplication sharedApplication].statusBarOrientation = 1

[UIScreen mainScreen].bounds.size = 414x736

after first rotation:

[UIDevice currentDevice].orientation = 4

[UIApplication sharedApplication].statusBarOrientation = 4

[UIScreen mainScreen].bounds.size = 736x414

after second rotation:

[UIDevice currentDevice].orientation = 1

[UIApplication sharedApplication].statusBarOrientation = 4

[UIScreen mainScreen].bounds.size = 736x414

Now obviously, after the second rotation, the device is back in portrait mode - well not according to the interface orientation and the screen bounds...

Am I missing something here?

I have had this issue in the past and have concluded that when you set up an observer to the UIDeviceOrientationDidChangeNotification the method you specify is called before all attributes change to reflect the new orientation. The way I dealt with it is to create a function which runs a block of code after a delay and then call:

- (void)deviceOrientationDidChange:(NSNotification *)note
{
    RHRunBlockAfterDelay(0.5, ^{
        // Execute relevant code...
    });
}

The delay function is a wrapper around a call to [self performSelector:@selector(mySel) afterDelay:delay withObject:block]; defined in a separate Functions.h .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM