iOS 7 使用CGAffineTransformMakeRotation在autolayout布局下旋转图片变形.
来源:互联网 发布:淘宝卖家常用app 编辑:程序博客网 时间:2024/06/06 02:31
今天将项目的布局换成了autolayout,结果遇到一个很奇葩的问题,使用CGAffineTransformMakeRotation旋转图片时,在iOS 8以上的版本都没有问题,但是在iOS 7上出现了怪怪的效果.想都不用想肯定是autolayout的问题喽,简单粗暴的方法,换回手码呗.可是对于一个懒货来说,能拖线解决的绝对不手码.因为不同于之前了嘛,现在4种屏幕了,手码好累
错误原因: 约束设置的是水平和垂直位置固定,距离左右边距固定,等比例拉伸.约束如下:
因为图片是正方形的,设置距离边距固定值的话,转到角角处图片就给压缩了.(手残,大家凑合看吧) 有人会问,为什么在iOS 8以上就没问题呀?只能告诉你苹果在高版本上处理了这个比较不符合常理的问题吧
解决办法:
1. 上面说的,简单粗暴的方法:关掉autolayout,使用纯手码
2. 你可以偷点懒,因为高版本的没有问题,只需要适配一下低版本就好了.思路是不设置边距就不会拉伸了,所以设置水平和垂直距离然后固定死大小就好了.当然你不能在storyboard中同时设置这两种,所以只能手码了,不过肯定比你纯手码简单.
//箭头适配
if ([UIDevicecurrentDevice].systemVersion.floatValue <8.0) {
NSMutableArray* cons = [NSMutableArrayarray];
for (NSLayoutConstraint* conin self.view.constraints)
if (con.firstItem ==self.arrow || con.secondItem ==self.arrow)
[consaddObject:con];
[self.viewremoveConstraints:cons];
[self.arrowremoveConstraints:self.arrow.constraints];
[self.viewaddConstraint:
[NSLayoutConstraintconstraintWithItem:self.arrowattribute:NSLayoutAttributeCenterXrelatedBy:0toItem:self.viewattribute:NSLayoutAttributeLeftmultiplier:1constant:self.arrow.center.x]];
[self.viewaddConstraint:
[NSLayoutConstraintconstraintWithItem:self.arrowattribute:NSLayoutAttributeCenterYrelatedBy:0toItem:self.viewattribute:NSLayoutAttributeTopmultiplier:1constant:self.arrow.center.y]];
[self.arrowaddConstraint:
[NSLayoutConstraintconstraintWithItem:self.arrowattribute:NSLayoutAttributeWidthrelatedBy:0toItem:nilattribute:0multiplier:1constant:self.arrow.bounds.size.width]];
[self.arrowaddConstraint:
[NSLayoutConstraintconstraintWithItem:self.arrowattribute:NSLayoutAttributeHeightrelatedBy:0toItem:nilattribute:0multiplier:1constant:self.arrow.bounds.size.height]];
}
注意: 别人说设置锚点,其实没有用的.
_arrow.layer.anchorPoint =CGPointMake(0.5,0.5);
- iOS 7 使用CGAffineTransformMakeRotation在autolayout布局下旋转图片变形.
- 图片旋转的角度问题 CGAffineTransformMakeRotation
- iOS开发笔记--CGAffineTransformMakeRotation 实现旋转
- iOS开发笔记--CGAffineTransformMakeRotation 实现旋转
- UIView在AutoLayout下的布局过程
- iOS Autolayout 自动布局代码使用规则
- iOS UISlider 自定义及竖版实现&& CGAffineTransformMakeRotation 实现旋转
- 在UIScrollView中使用Autolayout布局(1)
- 在UIScrollView中使用Autolayout布局(2)
- 在UIScrollView中使用Autolayout布局
- CGAffineTransformMakeRotation 实现旋转
- CGAffineTransformMakeRotation旋转图像
- CGAffineTransformMakeRotation 实现旋转
- iOS解决拍照图片 会旋转 打开变形的问题
- ios Autolayout自动布局
- iOS AutoLayout 自动布局
- iOS AutoLayout 百分比布局
- iOS AutoLayout 百分比布局
- 基于注解和拦截器的权限控制
- 前台页面实现可选可编辑效果
- Android中Handler和AsyncTask
- LNAMP Linux+Apache+Nginx+MySQL+PHP
- HBA 卡 知识
- iOS 7 使用CGAffineTransformMakeRotation在autolayout布局下旋转图片变形.
- [Leetcode]N-Queens II
- Redis的Java客户端Jedis的八种调用方式(事务、管道、分布式)介绍
- UI测试
- Kaggle 机器学习竞赛冠军及优胜者的源代码汇总
- java执行字符串公式
- Android简单实现下拉刷新和上拉刷新
- Android之检测文本内容是否为空时左右摆动效果
- Git命令提交项目代码