iphone处理翻转[landscape]

方案1.

当没有UITabbar 时候 只需要重载两个方法即可,第一个方法是支持翻转,第二个方法调整根据不同的翻转模式,调整界面元素位置/或新做

一个view视图,为横向时候把横向视图添加到当前视图里面,翻转到纵向模式时候,把视图从当前视图移出[removefromsuperview]

 

 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

   //return YES;

   return ((interfaceOrientation == UIInterfaceOrientationPortrait)

             ||(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)

    ||(interfaceOrientation == UIInterfaceOrientationLandscapeRight));

}

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

方案2.

当有UITabbar时候需要需要重写对应的UITabBarController,首先要重写方法(BOOL)s <script src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" type="text/javascript"></script> <script src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" type="text/javascript"></script> houldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

 

 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    UIViewController *controller = self.selectedViewController;

    if ([controller isKindOfClass:[UINavigationController class]])

        controller = [(UINavigationController *)controller visibleViewController];

    return [controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];

 

 

}

其次在需要翻转的视图控制器中重写方案1中的两个方法

方案3:

如果有UITabbar,当处于横向模式时候,需要隐藏UITabbar,就不能采用方案1中的方法:向当前视图添加子视图,而需要向UIWindow添加视图,同时还需要设置和调整其横向视图坐标位置,同时隐藏当前纵向模式视图。

 

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

UIApplication*app=[UIApplication sharedApplication];

CGAffineTransform landscapeTransform;

if(toInterfaceOrientation!=UIInterfaceOrientationPortrait&&toInterfaceOrientation!= UIDeviceOrientationPortraitUpsideDown )

{

/*landscpecontroller view is the same level with self.view

both of them are the subview of the window. when we add the subview to

window, we can use the cgaffinetransform to chage the layout

*/

if(landScapeController==nil)

landScapeController=  [[PortfolioLandscape alloc] initWithNibName:@"PortfolioLandscape" bundle:nil];

landScapeController.colSortedTag=colSortedTag;

 

landScapeController.view.frame=CGRectMake(0, 0, 480, 320);

[[app keyWindow] addSubview:landScapeController.view];

app.statusBarHidden=YES;

self.tabBarController.view.hidden=true;

 

 

 

}

}

 

else 

{

 

self.tabBarController.view.hidden = false; 

app.statusBarHidden=NO;

}

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值