首页 > 代码库 > UIView利用hitTest添加点击事件

UIView利用hitTest添加点击事件

UIView利用hitTest添加点击事件

by 伍雪颖

技术分享

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint point = [[touches anyObject]locationInView:self.view];
    CALayer *layer = [self.view.layerhitTest:point];
   
if (layer ==self.blueView.layer) {
        [[[
UIAlertViewalloc]initWithTitle:@"Inside Blue Layer"
                                   
message:nil
                                  
delegate:nil
                         
cancelButtonTitle:@"OK"
                          otherButtonTitles:nil]show];
    }
}

UIView利用hitTest添加点击事件