简体   繁体   中英

how to rotate view when device orientation changes keeping the correct size of window

I want to support full device orientation in my iPad app which uses cocos2d. To accomplish this I thought I'll return YES for shouldAutorotateToInterfaceOrientation like before when I was working on apps without cocos2d, but in this case my view doesn't resize properly. To show you with what I ended up, it's example picture. 未调整大小的视图

you can see that orientation is landscape but the view is still portrait. Can anybody tell me what am I doing wrong?

Add the following function and perform respective changes

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    switch (toInterfaceOrientation) {
        case UIInterfaceOrientationPortrait:
            break;
        case UIInterfaceOrientationLandscapeLeft:
            break;
        case UIInterfaceOrientationLandscapeRight:
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            break;
        default:
            break;
    }
}

You have to set the autosize property of your view. the quick way is to set it in the "size inspector" 尺寸检查器

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