我必须在点击按钮的特定区域时执行操作。实际上在只有粉红色可见的区域。不在那个区域之外。请查看随附的图片以及此消息,如果我有任何不清楚的地方,请告诉我。
问问题
166 次
3 回答
0
您可以添加自定义选择器,然后在那里获得接触点。然后检查该点是否在您的特定区域内。
[pinkButton addTarget:self action:@selector(buttonTouched:withEvent:) forControlEvents: UIControlEventTouchDown];
//Define the area here or get the exact frame if it is already a UIView
CGRect frameOfSpecificArea = CGRectMake(10, 20, 30, 40);
- (void)buttonTouched:(UIButton *)sender withEvent:event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint tapPoint = [touch locationInView:sender];
NSLog(@"Pink Button touched x : %f y : %f", tapPoint.x, tapPoint.y);
BOOL pointIsInside = CGRectContainsPoint(frameOfSpecificArea, tapPoint);
if(pointIsInside) {
NSLog(@"Yeah, i'm a great iOS-Developer, i can check if a point is inside a CGRect!");
}
}
于 2013-11-06T08:36:04.900 回答
0
您需要创建自定义 UIButton 类并添加方法:
-(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if(![super pointInside:point withEvent:event]) return NO;
return [bezierPath containsPoint:point];
}
bazierPath 可见区域你的按钮。看这个链接文档
于 2013-11-06T08:59:51.340 回答
0
您应该继承 UIButton 并覆盖它- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
是区域几何的基础或访问按钮的图像并检查某个点的颜色。
看看这个:OBShapedButton
于 2013-11-06T08:11:50.690 回答