刚入职新公司,就看看新公司代码+熟悉环境,闲来无事自己瞎捣鼓捣鼓
不废话,切入正题
在scrollview上加一个tablevew,scrollview水平滑动,tableview支持滑动删除,此时两者滑动冲突
直接贴代码吧
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
UIView *view = touch.view;
if ([view isKindOfClass:[UITableView class]] || [@"UITableViewCellContentView" isEqualToString:[[view class] description]] )
{
return NO;
}
return YES;
}
顺便提及一下:
在UIView上面加scrollView,scroll里面加customView (UIview),UIView上面加拖拽手势,使customView能够拖拽移动,解决scrollView和UIPanGestureRecognizer的冲突
viewController对应的view加手势UIPanGestureRecognizer
- (IBAction)touchDragGesture:(UIPanGestureRecognizer *)sender {
CGPoint point = [sender locationInView:self.scrollView];
if (sender.state == UIGestureRecognizerStateBegan) {
for (UIView *subView in [self.scrollView subviews]) {
if ([subView isKindOfClass:[customView class]]) {
//do something
}
}
}else if (sender.state == UIGestureRecognizerStateEnded) {
//do something
}else{
//do something
}
}
在scrollview里面
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *result = [super hitTest:point withEvent:event];
NSArray *subViews = self.subviews;
for (UIView *subView in subViews) {
if ([subView isKindOfClass:[customView class]]) {
customView *table = (customView *)subView;
CGPoint buttonPoint = [table convertPoint:point fromView:self];
if ([table pointInside:buttonPoint withEvent:event])
{
return [self superview];
}
}
}
return result;
}
ok,完工!