[英]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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.