IOS基础知识记录七(iphone手机横屏、竖屏)

iphone手机旋转屏幕时,对视图进行切换
如:iPhone手机 Music在纵向模式和横向模式显显示播放列表方式的差异

1.创建Simple View Application一个项目
然后在添加一个UIView 标签设置为 landscape view.而默认的view设置为portrait view
把新加的view 托放到和View Controller同一级

2.然后编辑portrait View 在里面设置布局和样式,设置后把portrait View 托到View Controller 同一级, 把landscape View拖放到View Controller下。开始编辑landscape View

3.编辑成功后, 可以设置该两个view里面公共的属性和方法

4.在ViewController里面设置两个视图进行切换。如:


//首先在ViewController.m里面加入常量定义
#define CRotate  (3.1415926/180.0)

//改方法在切换屏幕时, 进行调用
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    
    [super willRotateToInterfaceOrientation:toInterfaceOrientation
                                   duration:duration];
    
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.view = landscapeView;
        self.view.transform = CGAffineTransformMakeRotation(CRotate*90);
        self.view.bounds = CGRectMake(0, 0, 480, 300);
        
    }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        self.view = landscapeView;
        self.view.transform = CGAffineTransformMakeRotation(CRotate*(-90));
        self.view.bounds = CGRectMake(0, 0, 480, 300);
        
    }else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
        self.view = portraitView;
        self.view.transform = CGAffineTransformMakeRotation(0);
        self.view.bounds = CGRectMake(0, 0, 320, 460);
  
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值