关于iphone和ipad横屏竖屏 适配问题

首先 先在viewWillAppear 里面 注册通知

- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    //注册屏幕旋转 消息通知

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(changeFrames:)

                                                 name:UIDeviceOrientationDidChangeNotification

                                               object:nil];

    }

viewDidLoad 初始化控件 

收到通知后

//收到通知后改变view坐标

-(void)changeFrames:(NSNotification *)notification

{

    CGRect rect = [UIScreen mainScreen].bounds;

    

    if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait

        || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown)

    {

        NSLog(@"portrait");

        _fancyTabBar.frame=CGRectMake(rect.size.width-300,rect.size.height-300, 300, 300);

    }

    else

    {

        NSLog(@"横屏");

        _fancyTabBar.frame=CGRectMake(rect.size.height-40,rect.size.width-550, 300, 300);

    }

}

如果是ipad 版

//收到通知后改变view坐标

-(void)changeFrames:(NSNotification *)notification

{

    CGRect rect = [UIScreen mainScreen].bounds;

    

    if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait)

    {

        NSLog(@"竖屏home在下");

        _fancyTabBar.frame=CGRectMake(rect.size.width-550,rect.size.height-550, 600, 700);

    }

    else if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown)

    {

        NSLog(@"竖屏home在下");

        _fancyTabBar.frame=CGRectMake(rect.size.width-550,rect.size.height-550, 600, 700);

        

    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft ){

        

        NSLog(@"横屏home在左");

        _fancyTabBar.frame=CGRectMake(rect.size.height-300,rect.size.width-800, 600, 600);

 

        

    } else{

        

        NSLog(@"横屏home在右");

        _fancyTabBar.frame=CGRectMake(rect.size.height-300,rect.size.width-800, 600, 600);

    }

    

}

 

转载于:https://www.cnblogs.com/panfeng1104/p/4496974.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值