gpt4 book ai didi

ios - 由于某种原因,UIBezierPath 轮廓不断出现在 View 周围

转载 作者:行者123 更新时间:2023-11-29 04:06:08 24 4
gpt4 key购买 nike

下面的代码是我用来创建 subview “theSubview”的代码,我将其添加到父 View “parentView”中。

假设parentView有框架{ {0.0, 0.0}, {100.0, 100.0} }并且 subview 的框架为 { {20.0, 20.0}, {20.0, 20.0} }

问题是,当我的绘图完成时,我最终不仅得到蓝色箭头标记,而且在 subview 的框架上得到一个蓝色轮廓。

知道我做错了什么吗?

谢谢!



// theSubview
// My UIView subclass that is added to another view
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
}
return self;
}

- (void)drawRect:(CGRect)rect {

[self drawArrow];
}

- (void)drawArrow {
CGRect arrowRect;

arrowRect = self.bounds;
UIBezierPath *arrowPath = [UIBezierPath bezierPathWithRect:arrowRect];

// UIColor *backgrColor = [UIColor grayColor];
// [backgrColor setFill];
// [arrowPath fillWithBlendMode:kCGBlendModeNormal alpha:0.9f];

UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];


CGFloat thirdOfWidth = floorf(CGRectGetWidth(self.bounds) / 3);
CGFloat thirdOfHeight = floorf(CGRectGetHeight(self.bounds) / 3);

[arrowPath moveToPoint:CGPointMake(thirdOfWidth, thirdOfHeight)];
[arrowPath addLineToPoint:CGPointMake(thirdOfWidth * 2, thirdOfHeight + (floorf(thirdOfHeight/2)))];
[arrowPath addLineToPoint:CGPointMake(thirdOfWidth, thirdOfHeight * 2)];
[arrowPath setLineWidth:3.0f];
[arrowPath stroke];


}

最佳答案

呵呵,我明白了。 bezierPathWithRect 实际上使用该矩形作为路径创建了一个 bezierPath。矩形不是框架,b/c bezierPath 没有框架。b/c 它不是 UIView。

将上面的代码更改为

UIBezierPath *arrowPath = [UIBezierPath bezierPath];

修复它。

关于ios - 由于某种原因,UIBezierPath 轮廓不断出现在 View 周围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15195092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com