测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2015年1月 |
由Anton Bukov维护。
依赖 | |
JRSwizzle | >= 0 |
ObjcAssociatedObjectHelpers | >= 0 |
为 iOS CALayers 添加 UIViewAutoresize 支持,并提供快速将 UIView 转换为 CALayer 的方法
pod 'CALayer-AutoresizingMask'
在此 storyboard 或 xib 中不使用-autolayout,并使用您需要的自动调整大小遮罩。
在 IB 中使用CALayer替换非触摸的可视视图(UIView),记得它将递归地应用于所有子视图。
使用您旧的来访问可见层:
现在所有 CALayer
都具有 autoresizingMask
属性,类型为 UIVIewAutoresizing
,您也可以使用它!
它只是实现了简单的算法
将 self.frame
的 origin
和 size
比例增加到 superview
的frame
增加与每个轴上可伸缩元素数量的比值。这就是全部!
CGFloat dx = self.superlayer.bounds.size.width - self.superlayerSize.width;
CGFloat dy = self.superlayer.bounds.size.height - self.superlayerSize.height;
dx /= ((mask & UIViewAutoresizingFlexibleLeftMargin)?1:0)
+ ((mask & UIViewAutoresizingFlexibleWidth)?1:0)
+ ((mask & UIViewAutoresizingFlexibleRightMargin)?1:0);
dy /= ((mask & UIViewAutoresizingFlexibleTopMargin)?1:0)
+ ((mask & UIViewAutoresizingFlexibleHeight)?1:0)
+ ((mask & UIViewAutoresizingFlexibleBottomMargin)?1:0);
CGRect frame = self.frame;
frame.origin.x += (mask & UIViewAutoresizingFlexibleLeftMargin)?dx:0;
frame.origin.y += (mask & UIViewAutoresizingFlexibleTopMargin)?dy:0;
frame.size.width += (mask & UIViewAutoresizingFlexibleWidth)?dx:0;
frame.size.height += (mask & UIViewAutoresizingFlexibleHeight)?dy:0;
self.frame = frame;
欢迎您 fork、提交pull request、创建issue...