CKShapeView 是一个基于 CAShapeLayer
的 UIView
子类。
换句话说,它是一个能够渲染任意 CGPath
的视图。
它是完全可配置的 和可动画的,因此您可以在不进行子类化的情况下拥有自定义绘制的视图。
CKShapeView
拥有所有 CAShapeLayer
的属性,并添加了一个 hitTestUsingPath
属性,允许您使用路径而不是视图的边界进行点击测试。
CKShapeView *pieView = [[CKShapeView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
CGFloat width = CGRectGetWidth(pieView.bounds);
pieView.path = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(pieView.bounds, width/4, width/4)];
pieView.lineWidth = width/2;
pieView.fillColor = nil;
pieView.strokeColor = [UIColor blackColor];
[self.view addSubview:pieView];
UIViewAnimationOptions options = UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat;
[UIView animateWithDuration:1.0f delay:0.0f options:options animations:^{
pieView.strokeEnd = 0.0f;
} completion:nil];
CKShapeView 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。