UIview 的快照不显示圆弧和圆角

Posted

技术标签:

【中文标题】UIview 的快照不显示圆弧和圆角【英文标题】:snapshot from the UIview is not displaying arcs and roundrect corner 【发布时间】:2013-04-11 13:38:15 【问题描述】:

我正在通过 UIBezierPath 在 uiview 上制作弧线。弧线做得很好,但是当我拍摄此 UIView 的快照以共享弧线时,快照中没有显示。 uiview 显示为默认值,圆弧和圆角矩形不显示。这是快照的代码 CGSize sz = CGSizeMake(bottomview.frame.size.width, bottomview.frame.size.height);

    UIGraphicsBeginImageContext(sz);
    [bottomview.layer renderInContext:UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    resultImageView.image=image;

这是制作弧线的代码 UIBezierPath *aPathbottom = [UIBezierPath bezierPath];

[aPathbottom moveToPoint:CGPointMake(0, 262)];





[aPathbottom addLineToPoint:CGPointMake(0, 15)];
[aPathbottom addLineToPoint:CGPointMake(10, 10)];
[aPathbottom addLineToPoint:CGPointMake(20, 6)];
[aPathbottom addLineToPoint:CGPointMake(40, 3.5)];
[aPathbottom addLineToPoint:CGPointMake(60, 6)];
[aPathbottom addLineToPoint:CGPointMake(70, 10)];
[aPathbottom addLineToPoint:CGPointMake(80,15)];

[aPathbottom addLineToPoint:CGPointMake(80, 250)];
[aPathbottom addLineToPoint:CGPointMake(70, 256)];
[aPathbottom addLineToPoint:CGPointMake(60, 260.5)];
[aPathbottom addLineToPoint:CGPointMake(50, 264)];
[aPathbottom addLineToPoint:CGPointMake(55, 264.5)];
[aPathbottom addLineToPoint:CGPointMake(40, 265)];
[aPathbottom addLineToPoint:CGPointMake(45, 264.5)];
[aPathbottom addLineToPoint:CGPointMake(40, 264)];
[aPathbottom addLineToPoint:CGPointMake(20, 260.5)];
[aPathbottom addLineToPoint:CGPointMake(10, 256)];
[aPathbottom addLineToPoint:CGPointMake(0, 250)];
[aPathbottom closePath];


CAShapeLayer *maskLayerbottom = [CAShapeLayer layer];
maskLayerbottom.frame = bottomview.bounds;
maskLayerbottom.path = aPathbottom.CGPath;


bottomview.layer.mask = maskLayerbottom;

我不知道为什么会这样。谁能帮帮我。

问候 查克苏阿罗拉

【问题讨论】:

【参考方案1】:

我得到了我尝试过的答案[bottomview.layer addSublayer:maskLayerbottom]; 代替了bottomview.layer.mask = maskLayerbottom; 并且来自UIView 的快照正在显示弧。

【讨论】:

【参考方案2】:

你试过添加这个吗?

[bottomview.layer setMasksToBounds:YES];

【讨论】:

以上是关于UIview 的快照不显示圆弧和圆角的主要内容,如果未能解决你的问题,请参考以下文章

CAD导圆角

UIView clipsToBounds不起作用

未显示超级视图子视图 UIView 的角半径

NSAttributedString 背景颜色和圆角

UIView 没有出现在 xib 上

你如何从显示的键盘下获取 UIScreen 的快照?