不规则区域的点击事件判断

来源:互联网 发布:exsi虚拟机linux网络 编辑:程序博客网 时间:2024/05/21 10:25

不规则区域的点击事件判断

import "CircleView.h"@implementation CircleView- (instancetype)initWithCoder:(NSCoder *)aDecoder{    if (self = [super initWithCoder: aDecoder]) {//        self.layer.cornerRadius = 100;//        self.clipsToBounds = YES;        self.backgroundColor = [UIColor clearColor];    }    return self;}- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    UIAlertView * alert = [[UIAlertView alloc] initWithTitle: nil message: @"点击了目标区域" delegate: nil cancelButtonTitle: @"确认" otherButtonTitles: nil];    [alert show];}- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{    UIBezierPath * path = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0, 0, 200, 200)];    UIBezierPath *path0  = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:100 startAngle:0 endAngle:M_PI/3.0 clockwise:YES];     [path0 addLineToPoint:CGPointMake(100, 100)];    return [path0 containsPoint: point];}-(void)drawRect:(CGRect)rect{    [super drawRect:rect];    [[UIColor yellowColor]set];    UIBezierPath *path0  = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:100 startAngle:0 endAngle:M_PI/3.0 clockwise:YES];    [path0 addLineToPoint:CGPointMake(100, 100)];    path0.lineWidth = 3;    [path0 closePath];    [path0 fill];}
0 0
原创粉丝点击