iOS Core Animation - 图层几何学

Z坐标轴

CALayer存在三维坐标系,layer还存在zPosition属性,通过改变zPosition的值可以改变图层的顺序

Hit Testing

CALayer不能直接处理触摸或者手势事件,但是可以通过其他方法处理事件,-containPoint:和-hitTest;

区分点击图层那一部分

例1,-containPoint


- (void)viewDidLoad {
    [super viewDidLoad];
    CALayer *blueLayer = [[CALayer alloc] init];
    blueLayer.frame = CGRectMake(0, 0, 100, 100);
    blueLayer.backgroundColor = [UIColor blueColor].CGColor;
    [self.layerView.layer addSublayer:blueLayer];
    self.blueLayer = blueLayer;
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    CGPoint point = [[touches anyObject] locationInView:self.view];
    point = [self.layerView.layer convertPoint:point fromLayer:self.view.layer];
    if ([self.layerView.layer containsPoint:point]) {
        point = [self.blueLayer convertPoint:point fromLayer:self.layerView.layer];
        if ([self.blueLayer containsPoint:point]) {
            NSLog(@"blueLayer");
        }else{
            NSLog(@"layerView");
        }
    }
}

 

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    CGPoint point = [[touches anyObject] locationInView:self.view];
    CALayer *layer = [self.layerView.layer hitTest:point];
    if (layer == self.blueLayer) {
      NSLog(@"blueLayer");
    }else if (layer == self.layerView.layer){
        NSLog(@"layerView");
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值