Autosize 2 (恒屏和自动旋转)

自动旋转有如下几种实现方法:
1、使用自动调整属性进行旋转:

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

return YES;

}
该方法利用系统自动实现的旋转,view上的元素位置不会改变,可能有的元素会移到屏幕外。
2、在旋转时对视图进行重构(重新设置视图上各个元素的坐标位置)

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientationduration:(NSTimeInterval)duration {    

    UIInterfaceOrientation interfaceOrientation self.interfaceOrientation;

    if (interfaceOrientation == UIInterfaceOrientationPortrait 

        || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)

    {

        button1.frame CGRectMake(2020125125);

        button2.frame CGRectMake(17520125125);

        button3.frame CGRectMake(20168125125);

        button4.frame CGRectMake(175168125125);

        button5.frame CGRectMake(20315125125);

        button6.frame CGRectMake(175315125125);

    }

    else 

    {

        button1.frame CGRectMake(2020125125);

        button2.frame CGRectMake(20155125125);

        button3.frame CGRectMake(17720125125);

        button4.frame CGRectMake(177155125125);

        button5.frame CGRectMake(32820125125);

        button6.frame CGRectMake(328155125125);

    }

}

 

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

 

05 Autosize 2 (恒屏和自动旋转) - 阿帕奇 - XGG XGG 05 Autosize 2 (恒屏和自动旋转) - 阿帕奇 - XGG XGG
 

 

有两个函数:

-(void) willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

该方法在发生在旋转动画完全完成之前调用。

-(void) willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientationduration:(NSTimeInterval)duration

此方法在旋转开始之后,最后的旋转动画发生之前调用。

3、切换视图

这种方法使用于比较复杂的界面,是需要分别设计横向模式和纵向模式,然后在使用的过程中自动切换。

InterfaceOrientation有四个属性:Portait, LandscapeLeft, LandscapeRight, PortaitUpsideDown.


 

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)

interfaceOrientation duration:(NSTimeInterval)duration {

    if (interfaceOrientation == UIInterfaceOrientationPortrait)

    {

        self.view self.portrait;

        self.view.transform CGAffineTransformIdentity;

        self.view.transform CGAffineTransformMakeRotation(degreesToRadian(0));

        self.view.bounds CGRectMake(0.00.0300.0480.0);

    }

    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)

    {

        self.view self.landscape;

        self.view.transform CGAffineTransformIdentity;

        self.view.transform CGAffineTransformMakeRotation(degreesToRadian(-90));

        self.view.bounds CGRectMake(0.00.0460.0320.0);

    }

    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)

    {

        self.view self.portrait;

        self.view.transform CGAffineTransformIdentity;

        self.view.transform CGAffineTransformMakeRotation(degreesToRadian(180));

        self.view.bounds CGRectMake(0.00.0300.0480.0);

    }

    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)

    {

        self.view self.landscape;

        self.view.transform CGAffineTransformIdentity;

        self.view.transform 

        CGAffineTransformMakeRotation(degreesToRadian(90));

        self.view.bounds CGRectMake(0.00.0460.0320.0);

    }

}

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     return YES;

 }

因为在上面的代码中使用到了Core Graphics框架,因此要把该框架连接到该项目中,具体的方法是:在Resources上面点右键Add->Existing Frameworks。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值