iOS 点击图片的坐标响应对应的事件
2018-03-30 本文已影响9人
星星编程
1、不规则形状
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
[self.mapImageView addGestureRecognizer:tap];
self.scaleW=ScreenWidth/375;
self.scaleH=ScreenHeight/667;
}
-(UIBezierPath *)path1H{
if (_path1H==nil) {
_path1H=[[UIBezierPath alloc] init];
[_path1H moveToPoint:CGPointMake(303*self.scaleW,222*self.scaleH)];
[_path1H addLineToPoint:CGPointMake(335.5*self.scaleW, 249*self.scaleH)];
[_path1H addLineToPoint:CGPointMake(274*self.scaleW, 316.5*self.scaleH)];
[_path1H addLineToPoint:CGPointMake(242.5*self.scaleW, 318*self.scaleH)];
[_path1H addLineToPoint:CGPointMake(228*self.scaleW, 303*self.scaleH)];
[_path1H closePath];
}
return _path1H;
}
-(void)tapClick:(UITapGestureRecognizer *)tapGesture{
CGPoint point=[tapGesture locationInView:self.mapImageView];
if ([self.path1H containsPoint:point]) {
NSLog(@"测试坐标点path1H%f---%f",point.x,point.y);
}
}
2、矩形
bool CGRectContainsPoint(CGRect rect,CGPoint point)
bool CGRectContainsRect(CGRect rect1, CGRect rect2)