iOS 7 使用CGAffineTransformMakeRotation在autolayout布局下旋转图片变形.

今天将项目的布局换成了autolayout,结果遇到一个很奇葩的问题,使用CGAffineTransformMakeRotation旋转图片时,在iOS 8以上的版本都没有问题,但是在iOS 7上出现了怪怪的效果.想都不用想肯定是autolayout的问题喽,简单粗暴的方法,换回手码呗.可是对于一个懒货来说,能拖线解决的绝对不手码.因为不同于之前了嘛,现在4种屏幕了,手码好累委屈


错误原因: 约束设置的是水平和垂直位置固定,距离左右边距固定,等比例拉伸.约束如下:


因为图片是正方形的,设置距离边距固定值的话,转到角角处图片就给压缩了.(手残,大家凑合看吧) 有人会问,为什么在iOS 8以上就没问题呀?只能告诉你苹果在高版本上处理了这个比较不符合常理的问题吧偷笑



解决办法:

1. 上面说的,简单粗暴的方法:关掉autolayout,使用纯手码

2. 你可以偷点懒,因为高版本的没有问题,只需要适配一下低版本就好了.思路是不设置边距就不会拉伸了,所以设置水平和垂直距离然后固定死大小就好了.当然你不能在storyboard中同时设置这两种,所以只能手码了,不过肯定比你纯手码简单.

    // 箭头适配

    if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {

        NSMutableArray* cons = [NSMutableArray array];

        for (NSLayoutConstraint* con in self.view.constraints)

            if (con.firstItem == self.arrow || con.secondItem == self.arrow)

                [cons addObject:con];

        

        [self.view removeConstraints:cons];

        [self.arrow removeConstraints:self.arrow.constraints];

        [self.view addConstraint:

         [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeCenterX relatedBy:0 toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:self.arrow.center.x]];

        [self.view addConstraint:

         [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:self.arrow.center.y]];

        [self.arrow addConstraint:

         [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:0 multiplier:1 constant:self.arrow.bounds.size.width]];

        [self.arrow addConstraint:

         [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeHeight relatedBy:0 toItem:nil attribute:0 multiplier:1 constant:self.arrow.bounds.size.height]];

    }


注意: 别人说设置锚点,其实没有用的.

_arrow.layer.anchorPoint = CGPointMake(0.5, 0.5);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值