简体   繁体   中英

Transitioning UIViews

I am using Facebook SDK in my game in order to post some scores on Facebook. My code is using the Cocos2D framework so I had to add some code to enable the use of UIView. Everything works fine except that the view appears in portrait orientation despite the fact that my nibs attributes indicate landscape, the ShouldautoRotate method returns landscape, and the app orientation is also the to landscape. here is the code that set up the view:

// share to facebook methods
-(void)shareFacebookSelected
{
[[SimpleAudioEngine sharedEngine]stopBackgroundMusic];
[[CCDirector sharedDirector] pause];

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    myViewController1 = [[HFViewController alloc] initWithNibName:@"HFViewController_iPhone" bundle:nil];

 } else {
     myViewController1 = [[HFViewController alloc] initWithNibName:@"HFViewController_iPad" bundle:nil];
 }


UIWindow* window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];


[[[CCDirector sharedDirector]view] removeFromSuperview];

myViewController1.view.hidden = false;

[window addSubview:myViewController1.view];


[UIView commitAnimations];

}

I also enabled a button to return to the normal cocos game and remove the UIView but upon return even my main game orientation has changed to portrait.

any ideas???

The following lines solved my problem:

#define DegreesToRadians(x) ((x) * M_PI / 180.0)
CGRect screenRect = [[UIScreen mainScreen]bounds];
 myViewController1.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90));
myViewController1.view.hidden = false;
myViewController1.view.frame = screenRect;

I basically rotated the view 90 degrees, not the most elegant solution, just brute force but it works. I would still like to understand why it renders the way it does, oh well

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