有没有办法制作UIView轮?

时间:2016-03-16 21:32:34

标签: ios swift uiview

我不是说让它看起来很圆。我知道cornerRadiusmasksToBounds。当你使用它们时,视图实际上只是一个隐藏角落的矩形。我需要一个字面上的视图。这可能吗?

1 个答案:

答案 0 :(得分:0)

假设您正在此之后,因为您只想在圈内允许触摸事件,而不是在矩形边缘...这可以通过覆盖pointInside UIView方法来完成只接受定义路径中的点。

这可以通过存储圆圈的边缘(或任何UIBezierPath)然后检查该路径是否包含给定点来完成:

@interface CircleView : UIView

@propery (nonatomic, strong) UIBezierPath *edgePath; // init this with your path details

@end

@implementation CircleView

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    return [edgePath containsPoint:point];
}

@end