IOS 獲取手勢點選的座標
阿新 • • 發佈:2019-02-07
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(sigleTappedPickerView:)];
[singleTap setNumberOfTapsRequired:1];
[selfaddGestureRecognizer:singleTap];
singleTap.delegate =self;
- (void)sigleTappedPickerView:(UIGestureRecognizer
{
//取得所點選的點的座標
CGPoint point = [senderlocationInView:self];
// 判斷該點在不在區域內
if (CGRectContainsPoint(CGRectMake(0,FIXED_PICKER_SELECTED_ORIGNALY,FIXED_PICKER_SELECTED_WIDTH, FIXED_PICKER_SELECTED_HEIGHT), point))
{
///// Do what you want
}
}
)
UITouch類中包含如下成員函式:
- (CGPoint)locationInView:(UIView *)view:
CGRectContainsPoint :一個點是否包含在矩形中