屏幕旋转

一、屏幕旋转的支持

处理屏幕旋转支持的代码在ViewController.m文件里,函数如下。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    //return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    return YES;
}


语句:return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);表示不支持home键在上面。

改成return YES;则支持所有屏幕方向。

另外,

    UIInterfaceOrientationPortrait-------表示home键在下(默认的纵向模式)

    UIInterfaceOrientationPortraitUpsideDown-------表示home键在上

    UIInterfaceOrientationLandscapeLeft-------表示home键在左

    UIInterfaceOrientationLandscapeRight---------表示home键在右


二、旋转屏幕事件

    (1)willAnimateFirstHalfOfRotationTolnterfaceOrientation:    旋转前触发(直接添加下列函数即可)

        - (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration{

            //......

        }

        参数toInterfaceOrientation表示窗口即将改变的方向,

        参数duration表示前一半旋转的持续时间,单位秒。

    (2)willAnimateSecondHalfOfRotationFromInterfaceOrientation:    旋转进行到一半时触发

    (3)willRotateToInterfaceOrientation:    等于连续触发上述两次事件

    (4)willAnimateRotationToInterfaceOrientation:    在旋转动画开始前触发

【注意】1.willRotate必须在willAnimate前;

             2.如需处理willAnimate,则willAnimateFirst和willAnimateSecond不再触发。


三、运行期间旋转屏幕

    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];


四、程序加载时设置屏幕方向

1.png




【注意】会触发屏幕旋转事件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值