IOS第15天(2,事件处理hitTest练习)

***hitTest 获取最合适的点

@implementation HMGreenView


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s",__func__);
}

//   获取 最合适的 点的view 
//- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
//{
//    // 把自己的点转换按钮的坐标系上的点
//    CGPoint buttonPoint = [self convertPoint:point toView:_button];
//    
//    if ([_button pointInside:buttonPoint withEvent:event]) return nil;  //自己 不是 最合适的点
//
//    
//    return [super hitTest:point withEvent:event];
//}

//  判断是不是最合适的点
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    // 把左边控件上的点转换为右边上边控件的点
//    CGPoint buttonPoint = [self convertPoint:point toView:_button];
    
    // 从右边这个view上的点转换为坐标上的点
    CGPoint buttonPoint =[_button convertPoint:point fromView:self];
    if ([_button pointInside:buttonPoint withEvent:event]) return NO;    //自己不是最合适的点
    
    
    return [super pointInside:point withEvent:event];
}


@end

 

posted @ 2015-08-31 15:32  iso  阅读(200)  评论(0编辑  收藏  举报