当方向改变时,Cocos2d手动旋转UIKit

时间:2013-02-23 21:28:42

标签: cocoa-touch cocos2d-iphone rotation

我需要对此代码进行哪些更改才能使其在Cocos2d中运行?在方向改变时手动旋转,可以很好地保持触摸。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
        [self changeTheViewToPortrait:YES andDuration:duration];
    }
    else if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
        [self changeTheViewToPortrait:NO andDuration:duration];
    }
}

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    if(portrait){
        //change the view and subview frames for the portrait view
        tabBar.frame = CGRectMake(0, 420, 320, 40);
    }
    else {
        //change the view and subview  frames for the landscape view
        tabBar.frame = CGRectMake(0, 260, 480, 40);
    }
    [UIView commitAnimations];
}

0 个答案:

没有答案