UITabbarcontroller里的viewcontroller旋转控制

实现UITabbarcontroller 的类方法, 可以用里面的nag push到另一个view时,旋转

不需要再在各个viewcontroll中 另外实现此方法


@implementation UITabBarController(Rotation)


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    

    if([self.selectedViewController isKindOfClass:[UINavigationController class]]){

        return [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];

    }

    

 else {

    

    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 

}

}

@end



实现tabbarcontroll 某一个viewcontroll (MVLCMovieListViewController)单独旋转

不需要再在各个viewcontroll中 另外实现此方法


@implementation UITabBarController(Rotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    

    if([self.selectedViewController isKindOfClass:[UINavigationController class]]){

        for (UIViewController *viewcontroller in [(UINavigationController*)self.selectedViewController viewControllers])

        {

            if ([viewcontroller isKindOfClass:[MVLCMovieListViewController class]]) {

                return [viewcontroller shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];

            }

            else

                return [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];


        }

                

    } else {

    //    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];

  //      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];


    }

 //   return NO;

        return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];

}


@end



//2013.08.21新增 导航中 禁止某个viewController旋转  可能会造成view的位置改变

先添加这个类别
@implementation UINavigationController (Rotation)
- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}
@end

 

再在.m文件中添加如下代码
//禁止旋转屏幕
-(BOOL)shouldAutorotate
{
    return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

 

参考 http://blog.csdn.net/yiyaaixuexi/article/details/8035014

//
//ios6中 禁止某个view旋转 不会造成位置偏移
-(NSUInteger)supportedInterfaceOrientations{
    if([[self topViewController] isKindOfClass:[self.superclass class]])
        return UIInterfaceOrientationMaskAllButUpsideDown;
    else
        return UIInterfaceOrientationMaskPortrait;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值