gpt4 book ai didi

ios - 贝塞尔路径在 View 中不可见

转载 作者:行者123 更新时间:2023-11-28 19:03:02 24 4
gpt4 key购买 nike

我从斯坦福 ios7 类(class)中复制了以下代码,用于向 View 添加贝塞尔曲线路径。然而,当我将此代码包含在 ViewDidLoad 中时,它没有在屏幕上显示任何内容

 UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(75, 10)];
[path addLineToPoint: CGPointMake(160, 150)];
[path addLineToPoint:CGPointMake(10, 150)];
[[UIColor whiteColor] setStroke];
[[UIColor whiteColor] setFill];
[path stroke];
[path fill];

之后,我添加了这个日志语句 NSLog(@"path: %@", path); 打印了这个不祥的错误消息。

This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

你能解释一下我做错了什么吗?

最佳答案

我通过创建一个 CAShapeLayer 并将其添加为 View 层的子层来完成此操作。巧妙的是,您可以使用 UIBezierPath 的 CGPath 属性来设置图层。

    CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = path.CGPath;
layer.strokeColor = [UIColor whiteColor].CGColor;
[self.view.layer addSublayer:layer];

关于ios - 贝塞尔路径在 View 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23065217/

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