[英]Table view doesn't scroll when I use gesture recognizer
My app has a table view (with a scroll-into of course) and this view slides on and off with a gesture recognizer (like on the Facebook app). 我的应用程序有一个表格视图(当然还有滚动),这个视图使用手势识别器(就像在Facebook应用程序上一样)打开和关闭。
If I use a button to slide [the table view onto the screen], it works fine but when I use a gesture recognizer, the table view can't be scrolled anymore. 如果我使用按钮将[表格视图滑动到屏幕],它可以正常工作,但是当我使用手势识别器时,表格视图不能再滚动。
Here is the code of gesture recognizer with the problem: 以下是具有问题的手势识别器代码:
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
Somebody have an idea? 有人有想法吗?
Your gesture is probably preventing the scroll view gesture from working because by default only 1 gesture can be recognising at a time. 您的手势可能会阻止滚动视图手势的工作,因为默认情况下,一次只能识别1个手势。 Try adding yourself as the delegate of your gesture and implementing:
尝试添加自己作为手势的代表并实施:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
self.slidingViewController.panGesture.delegate = self;
also, add <UIGestureRecognizerDelegate>
to the list of protocols you implement 另外,将
<UIGestureRecognizerDelegate>
添加到您实现的协议列表中
I have used UIPangesture in my UItableview and to avoid this gesture I have used below delegate, 我在UItableview中使用了UIPangesture,并且避免了我在代理下面使用的这个手势,
//This method helped me stopped up/down pangesture of UITableviewCell and allow only vertical scroll
override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
let translation = panGestureRecognizer.translationInView(superview)
if fabs(translation.x) > fabs(translation.y) {
return true
}
return false
}
return false
}
Here is the swift version: 这是快速版本:
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
I had same issue of defining long press gesture on table view and not being able to scroll table when I long press on it. 我有同样的问题,在桌面视图上定义长按手势,当我长按它时无法滚动表格。
Fixed by: 修正:
1- adding UIGestureRecognizerDelegate
1-添加
UIGestureRecognizerDelegate
2- adding gesture.delegate = self (after you defined the long press gesture)
2-添加
gesture.delegate = self (after you defined the long press gesture)
3- adding this function: 3-添加此功能:
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {return true}
If I get it right the view that you're adding the gesture recognizer to is the table view. 如果我说得对,那么你要添加手势识别器的视图就是表格视图。 By default the
UIScrollView
(and implicitly UITableView
) class uses the pan gesture recognizer for the scroll and your gesture recognizer interferes with that. 默认情况下,
UIScrollView
(和隐式UITableView
)类使用平移手势识别器进行滚动,并且您的手势识别器会干扰它。 If you use another view as a container for the table view and you're adding the pan gesture recognizer to it should work. 如果您使用另一个视图作为表视图的容器,并且您要将平移手势识别器添加到它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.