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

标签 ios objective-c

我从斯坦福 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/

相关文章:

ios - 如何在 JTCalender 中设置日期限制?

ios - 在 iOS 中使用 map 进行转弯导航

objective-c - 桌面上的 AVAudioSession?

iphone - 标签栏和导航 Controller 内的 MKMapView 隐藏了 Google 品牌

ios - Cocos2d 2.0 横向 : howto?

ios - 在 iPad 中从纵向模式切换到横向模式时如何正确加载图像和按钮

ios - CoreStore 通过事务删除对象来更新关系。编辑不起作用

ios - 隐藏音量 HUD(避免使用加载 View )

ios - 从 CustomObject 数组获取值数组

ios - Watch App : [WCSession defaultSession]. isReachable 总是在后台应用程序上检索 'FALSE' 状态?