现在的位置: 首页 > 综合 > 正文

强制iphone界面马上旋转(转载)

2018年02月14日 ⁄ 综合 ⁄ 共 1169字 ⁄ 字号 评论关闭

From: http://www.cnblogs.com/think/archive/2011/05/03/ForceViewRotateImmediatly.html

在现在的ios sdk中,我们一般通过UIApplication的setStatusBarOrientation:来进行View的强制旋转(当然,还要配合- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation),但是,setStatusBarOrientation并不一定马上会执行shouldAutorotateToInterfaceOrientation进行界面旋转,这时,有个小技巧可以让界面马上旋转过来,那就是调用一下 UINavigationController的presentModalViewController:animated:

.........{
    
//为了马上旋转过来
    UINavigationController* nav = [[GurgleAppDelegate getAppDelegate] navigationController];
    UIViewController 
*controller = [[UIViewController alloc] init];
    UINavigationController 
*parentController = [[UINavigationController alloc] initWithRootViewController:controller];
    [nav presentModalViewController:parentController animated:NO];
    [controller dismissModalViewControllerAnimated:NO];
    [parentController release];
    [controller release];

}

 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
// Return YES for supported orientations.
    return viewOrientation == interfaceOrientation;

 

}  

抱歉!评论已关闭.