[英]How to fit CAShapeLayer
I`m developing iPhone app, where i using next code to round two corners of my layer : 我正在开发iPhone应用程序,在这里我使用下一个代码来环绕图层的两个角:
CAShapeLayer *backgroundMaskLayer = [CAShapeLayer layer];
UIBezierPath *backgroungMaskPath = [UIBezierPath
bezierPathWithRoundedRect:self.layer.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(10.0, 10.0)];
self.clipsToBounds = NO;
backgroundMaskLayer.frame = self.layer.bounds;
backgroundMaskLayer.path = backgroungMaskPath.CGPath;
backgroundMaskLayer.lineWidth = 2.0;
backgroundMaskLayer.strokeColor = [UIColor whiteColor].CGColor;
backgroundMaskLayer.fillColor = [UIColor whiteColor].CGColor;
[self.inputBackView.layer addSublayer:backgroundMaskLayer];
But circled layer doesn`t scale with other layers on different devices. 但是带圆圈的图层无法与其他设备上的其他图层缩放。
I`ve tried this: 我已经试过了:
backgroundMaskLayer.contentsScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.rasterizationScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.shouldRasterize = YES;
and this: 和这个:
- (void)layoutSubviews {
mylayer.frame = self.bounds;
}
Also i ve tried to make different combinations of constraints, but i
m still getting this on iPhone 6 (on iPhone 5, it is pretty enough): ve tried to make different combinations of constraints, but i
仍然在iPhone 6上得到它(在iPhone 5上就足够了):
where blue colour is my layer in xib file, on which I impose my CAShapeLayer * backgroundMaskLayer (white colour). 蓝色是我在xib文件中的图层,在上面施加了我的CAShapeLayer * backgroundMaskLayer(白色)。
How can i fix it? 我该如何解决?
Update your layoutSubviews method as: 将您的layoutSubviews方法更新为:
- (void)layoutSubviews
{
[super layoutSubviews];
UIBezierPath *backgroungMaskPath = [UIBezierPath
bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(10.0, 10.0)];
backgroundMaskLayer.path = backgroungMaskPath.CGPath;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.