如何适配 CAShapeLayer
How to fit CAShapeLayer
我正在开发 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];
但是圈出的图层不会与不同设备上的其他图层一起缩放。
我试过这个:
backgroundMaskLayer.contentsScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.rasterizationScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.shouldRasterize = YES;
还有这个:
- (void)layoutSubviews {
mylayer.frame = self.bounds;
}
我ve tried to make different combinations of constraints, but i
我还在 iPhone 6 上看到这个(在 iPhone 5 上,这已经足够了):
其中蓝色是我在 xib 文件中的图层,我在其上施加了我的 CAShapeLayer * backgroundMaskLayer(白色)。
我该如何解决?
将您的 layoutSubviews 方法更新为:
- (void)layoutSubviews
{
[super layoutSubviews];
UIBezierPath *backgroungMaskPath = [UIBezierPath
bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(10.0, 10.0)];
backgroundMaskLayer.path = backgroungMaskPath.CGPath;
}
我正在开发 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];
但是圈出的图层不会与不同设备上的其他图层一起缩放。
我试过这个:
backgroundMaskLayer.contentsScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.rasterizationScale = [UIScreen mainScreen].scale;
backgroundMaskLayer.shouldRasterize = YES;
还有这个:
- (void)layoutSubviews {
mylayer.frame = self.bounds;
}
我ve tried to make different combinations of constraints, but i
我还在 iPhone 6 上看到这个(在 iPhone 5 上,这已经足够了):
其中蓝色是我在 xib 文件中的图层,我在其上施加了我的 CAShapeLayer * backgroundMaskLayer(白色)。
我该如何解决?
将您的 layoutSubviews 方法更新为:
- (void)layoutSubviews
{
[super layoutSubviews];
UIBezierPath *backgroungMaskPath = [UIBezierPath
bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(10.0, 10.0)];
backgroundMaskLayer.path = backgroungMaskPath.CGPath;
}