`
lihao312
  • 浏览: 479607 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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);
  
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics