xcode AutoLayout






代码链接


Auto Layout 是IOS 6.0才开始引用的技术,如果要兼容IOS6.0以下程序,则不能启用Auto Layout,它能解决屏幕旋转界面呈现混乱的总是,

如果有人使用过网页的响应式布局的话,那么它感觉就与网页响应式布局相似,它不仅能设置控件的位置与大小,而且还可以放大,缩小处理。

如果是简单的设置则可以使用autolayout,如果是复杂的话,我觉得还是要通过代码实现,根据用户旋转屏幕。以上代码中没有写任何代码,全都是在

storyboard中完成。


以下是屏幕旋转后触发的事件。

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{

    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        UIInterfaceOrientation orientation=[[UIApplication sharedApplication] statusBarOrientation];
        //do whatever;
        CGRect rect;
        switch (orientation) {
            case UIInterfaceOrientationPortrait:
                NSLog(@"UIInterfaceOrientationPortrait");
                
                rect=self.topLeft.frame;
                rect.size.width=130;
                rect.size.height=200;
                self.topLeft.frame=rect;
                
                rect=self.topRight.frame;
                rect.origin.x=170;
                rect.size.width=130;
                rect.size.height=200;
                self.topRight.frame=rect;
                
                rect=self.bottom.frame;
                rect.origin.y=240;
                rect.size.width=280;
                rect.size.height=200;
                self.bottom.frame=rect;
                break;
                // doesn't supoort.
//            case UIInterfaceOrientationPortraitUpsideDown:
//                NSLog(@"UIInterfaceOrientationPortraitUpsideDown");
//                break;
            case UIInterfaceOrientationLandscapeLeft:
                NSLog(@"UIInterfaceOrientationLandscapeLeft");
               // break;
            case UIInterfaceOrientationLandscapeRight:
                NSLog(@"UIInterfaceOrientationLandscapeRight");
                //top left view;
                rect=self.topLeft.frame;
                rect.size.width=210;
                rect.size.height=120;
                self.topLeft.frame=rect;
                //top rigth view
                rect=self.topRight.frame;
                rect.origin.x=250;
                rect.size.width=210;
                rect.size.height=120;
                self.topRight.frame=rect;

                //bottom view
                rect=self.bottom.frame;
                rect.origin.y=160;
                rect.size.width=440;
                rect.size.height=120;
                self.bottom.frame=rect;
                
                break;
            default:
                break;
        }
        
        
    } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        //
        
        NSLog(@"rotation completed.");
    }];
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值