1.我选择定制圆角的方法是,利用UIBezierPath对象拿到路径,然后赋值给CAShapeLayer对象,最后利用视图的图层mask属性进行圆角定制。
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(12, 12)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = button.bounds;
maskLayer.path = maskPath.CGPath;
button.layer.mask = maskLayer;
2.使用Masnory进行布局,拿不到frame,所以上面的代码就因此无效。
3.我要定制的圆角是 UITableView 对象中的 heardView 和 cell,而且 两个视图的大小是自适应的,另外随着数据源的更新不同,这样的圆角的定制情况也会有所不同。那么这种情况下,使用 - setNeedsUpdateConstraints、- layoutIfNeeded 等方法拿到frame 再来进行圆角定制,也不现实。况且,性能上也不允许。
所以,我想问问,在这样的情况要求下,还可以使用什么方法来进行圆角定制。如果,你知晓的话,请在闲余之时回复一下,帮我解读解读。
谢谢啦、
高洛峰2017-04-18 09:41:58
To draw rounded corners, you must specify the size, or call the maskToBounds method, but everyone knows that this performance is the worst.
I think we should get the frame before drawing, and use other methods to optimize performance issues. (Similar to rewriting drawRect to reduce the view hierarchy, etc., or using instruments to analyze where the bottleneck is
In extreme cases, use frame hard calculation directly and do not use auto layout.
大家讲道理2017-04-18 09:41:58
The processing method in our project is to use a UIView with a rounded corner layer inside. This view establishes constraints with the view that requires rounded corners, and draws a Bezier curve in the layout subview of this rounded corner view
阿神2017-04-18 09:41:58
In fact, the best way is to directly add a picture with rounded corners to them, which has the best performance