【发布时间】:2016-02-10 08:53:06
【问题描述】:
我正在开发 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;
}
另外,ive tried to make different combinations of constraints, but im 还在 iPhone 6 上得到这个(在 iPhone 5 上,这已经足够了):
蓝色是我在 xib 文件中的图层,我在其上施加了我的 CAShapeLayer * backgroundMaskLayer(白色)。
我该如何解决?
【问题讨论】:
-
小点:如果您所做的只是圆角,您可以直接在 UIView 的图层上执行此操作,而不是使用额外的 CALayer 实例。
标签: ios objective-c calayer uibezierpath cashapelayer