不規則區域的點擊事件判斷

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/qq_28125515/article/details/50825288

不規則區域的點擊事件判斷

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];
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章