a. 判断点是否再某MutablePathRef路径里
- - (void)viewDidLoad {
- [super viewDidLoad];
- CGMutablePathRef pathRef=CGPathCreateMutable();
- CGPathMoveToPoint(pathRef, NULL, 4, 4);
- CGPathAddLineToPoint(pathRef, NULL, 4, 8);
- CGPathAddLineToPoint(pathRef, NULL, 10, 4);
- CGPathAddLineToPoint(pathRef, NULL, 4, 4);
- CGPathCloseSubpath(pathRef);
- CGPoint point=CGPointMake(5,7);
- CGPoint outPoint=CGPointMake(5,10);
- if (CGPathContainsPoint(pathRef, NULL, point, NO)) {
- NSLog(@"point in path!");
- }
- if (!CGPathContainsPoint(pathRef, NULL, outPoint, NO)) {
- NSLog(@"outPoint out path!");
- }
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];
}
浙公网安备 33010602011771号