这是在ios开发中常见的功能。即,touch移动事件,是移动到当前视图的子视图中,还是移动到当前视图以外了。
办法是,继承UIView,覆盖touchesMoved方法:
- (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");
}
}
}
本文介绍了一种在iOS开发中判断触控事件是否发生在视图内部还是移至视图外部的方法。通过继承UIView并覆盖touchesMoved方法实现,可以区分触控事件是在当前视图、子视图内发生还是移出了视图。
750

被折叠的 条评论
为什么被折叠?



