博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

点位置判断

Posted on 2013-03-17 14:38  酸梅拯救地球  阅读(204)  评论(0)    收藏  举报

 

a. 判断点是否再某MutablePathRef路径里

  1. - (void)viewDidLoad {  
  2.     [super viewDidLoad];  
  3.    
  4.     CGMutablePathRef pathRef=CGPathCreateMutable();  
  5.     CGPathMoveToPoint(pathRef, NULL, 4, 4);  
  6.     CGPathAddLineToPoint(pathRef, NULL, 4, 8);  
  7.     CGPathAddLineToPoint(pathRef, NULL, 10, 4);  
  8.     CGPathAddLineToPoint(pathRef, NULL, 4, 4);  
  9.     CGPathCloseSubpath(pathRef);  
  10.    
  11.     CGPoint point=CGPointMake(5,7);  
  12.     CGPoint outPoint=CGPointMake(5,10);  
  13.    
  14.     if (CGPathContainsPoint(pathRef, NULL, point, NO)) {  
  15.         NSLog(@"point in path!");  
  16.     }  
  17.    
  18.     if (!CGPathContainsPoint(pathRef, NULL, outPoint, NO)) {  
  19.         NSLog(@"outPoint out path!");  
  20.     } 

b.touch移动事件,是移动到当前视图的子视图中,还是移动到当前视图以外了

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch=[touches anyObject]; 
    if (![self pointInside:[touch locationInView:self] withEvent:nil]) { 
        NSLog(@"touches moved outside the view"); 
    }else { 
        UIView *hitView=[self hitTest:[[touches anyObject] locationInView:self] withEvent:nil]; 
        if (hitView==self) { 
            NSLog(@"touches moved in the view"); 
        }else{ 
            NSLog(@"touches moved in the subview"); 
        } 
    } 
}

c.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

{

  UITouch *touch = [[event allTouches] anyObject];
  CGPoint location = [touch locationInView:touch.view];
}