我制作了自定义圆形视图,如何检测圆形部分或圆形部分。我已尝试使用触摸
- (BOOL)validatePoint:(CGPoint)myPoint
{
// calculate how far from centre we are with Pythagorean
// √ a2 + b2
CGFloat a = abs(myPoint.x - (self.bounds.size.width/2));
CGFloat b = abs(myPoint.y - (self.bounds.size.height/2));
CGFloat distanceFromCentre = sqrt(pow(a,2) + pow(b,2));
if((distanceFromCentre > self.minRadiusSize) && (distanceFromCentre < radius)){
return YES;
}else{
// not inside doughnut
return NO;
}
}
但它检测整个视图。
答案 0 :(得分:1)
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
BOOL transparent=NO;
CGPoint touchLocation = [event locationInView:yourViewName];
if(CGRectContainsPoint(yourViewName.frame, touchLocation))
{
NSLog(@"Found =%d",i);
transparent=YES;
}
return transparent;
}
无论您是否在视线中点击,都会返回此信息。