ios中如何让uibutton内的非矩形区域响应uitouch
展开全部
举个例子,纯用button是肯定不行的了。比如说一个正方形边长为D,内中心有一个直径也为D的圆,我要求圆内科响应,圆外正方形部分不响应。圆的直径r = D/2.f;
1、给正方形_view添加UITapGestrureRecongnizer *tap
tap.delegate = self;
[_view addGestru...er:tap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
CGPoint point = [touch locationInView:_view];
//圆原点坐标为
CGFloat x1 = r;
CGFloat y2 = r;
//
CGFloat x2 = point.x;
CGFloat y2 = point.y;
if((y2-y1)²+(x2-x1)² < r²)
{
//圆内,响应点击
return YES;
}else
{
return NO;
}
}
两点间的距离 d,则 d² = (y2-y1)²+(x2-x1)²;
1、给正方形_view添加UITapGestrureRecongnizer *tap
tap.delegate = self;
[_view addGestru...er:tap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
CGPoint point = [touch locationInView:_view];
//圆原点坐标为
CGFloat x1 = r;
CGFloat y2 = r;
//
CGFloat x2 = point.x;
CGFloat y2 = point.y;
if((y2-y1)²+(x2-x1)² < r²)
{
//圆内,响应点击
return YES;
}else
{
return NO;
}
}
两点间的距离 d,则 d² = (y2-y1)²+(x2-x1)²;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询