切割UIView,并只让局部响应点击事件

22 篇文章 0 订阅
//
//  CutsomView.m
//  TestCutUIView
//
//  Created by liulibo on 13-9-17.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "CutsomView.h"
#import <QuartzCore/QuartzCore.h>

@implementation CutsomView


- (void)dwMakeBottomRoundCornerWithRadius:(CGFloat)radius
{
    CGSize size = self.frame.size;
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setFillColor:[[UIColor whiteColor] CGColor]];
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, size.width - radius, size.height);
    CGPathAddArc(path, NULL, size.width-radius, size.height-radius, radius, M_PI/2, 0.0, YES);
    CGPathAddLineToPoint(path, NULL, size.width, 0.0);
    CGPathAddLineToPoint(path, NULL, 0.0, 0.0);
    CGPathAddLineToPoint(path, NULL, 0.0, size.height - radius);
    CGPathAddArc(path, NULL, radius, size.height - radius, radius, M_PI, M_PI/2, YES);
    CGPathCloseSubpath(path);
    [shapeLayer setPath:path];
    CFRelease(path);
    self.layer.mask = shapeLayer;//layer的mask,顾名思义,是种位掩蔽,在shapeLayer的填充区域中,alpha值不为零的部分,self会被绘制;alpha值为零的部分,self不会被绘制,甚至不会响应touch
}

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
       // [self dwMakeBottomRoundCornerWithRadius:50];
        
        [self d2];
    }
    return self;
}

-(void)d2{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    CGSize size = self.frame.size;
    [shapeLayer setFillColor:[[UIColor whiteColor] CGColor]];
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 10);
     CGPathAddLineToPoint(path, NULL, 100, 0.0);
    CGPathAddLineToPoint(path, NULL, 150, 300);
    CGPathCloseSubpath(path);
    [shapeLayer setPath:path];
    CFRelease(path);
    self.layer.mask = shapeLayer;
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect
//{
//    //NO.4画正方形边框
//     
//      CGContextRef context = UIGraphicsGetCurrentContext();  
//     
//     CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
//     
//     CGContextSetLineWidth(context, 2.0);
//     
//     CGContextAddRect(context, CGRectMake(2, 2, 270, 270));
//     
//     CGContextStrokePath(context);
    
//}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 10);
    CGPathAddLineToPoint(path, NULL, 100, 0.0);
    CGPathAddLineToPoint(path, NULL, 150, 300);
    CGPathCloseSubpath(path);
    BOOL b = CGPathContainsPoint(path, NULL, point, YES);
    if (b) {
        return YES;
    }else
        return NO;
}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值