view自定义响应区域

UIBezierPath*_path;// 为全局变量

- (void)drawRect:(CGRect)rect {

[superdrawRect:rect];

//[self.image drawInRect:rect];

//把view裁剪成圆形

CGPointcenter =CGPointMake(CGRectGetMidX(rect),CGRectGetMidY(rect));

if(_path) {

_path=nil;

}

_path= [UIBezierPathbezierPath];

[_pathaddArcWithCenter:centerradius:rect.size.width/2.0startAngle:0endAngle:M_PI*2clockwise:YES];

[_pathclosePath];

//CAShapeLayer裁剪区域,超出区域部分不显示

//CAShapeLayer *shapeLayer = [CAShapeLayer layer];

//[shapeLayer setStrokeColor:[UIColor redColor].CGColor];

//shapeLayer.path = _path.CGPath;

//self.layer.mask = shapeLayer;

}

//点击在_path区域内响应,否则不响应

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event {

          BOOLres = [superpointInside:pointwithEvent:event];

         if(res) {

            if([_pathcontainsPoint:point]) {

                  returnYES;

               }

          returnNO;

         }

          returnNO;

}

你可能感兴趣的:(view自定义响应区域)