美文网首页
iOS 点击图片的坐标响应对应的事件

iOS 点击图片的坐标响应对应的事件

作者: 星星编程 | 来源:发表于2018-03-30 16:13 被阅读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)
    

    相关文章

      网友评论

          本文标题:iOS 点击图片的坐标响应对应的事件

          本文链接:https://www.haomeiwen.com/subject/yoyicftx.html