如何解决tableview和scrollview滑动冲突
1个回答
2016-08-22 · 知道合伙人软件行家
关注
展开全部
在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,完工!
直接贴代码吧
- (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,完工!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询