简体   繁体   English

使用手势识别器时,表格视图不会滚动

[英]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.

相关问题 MpMovieplayerController轻触手势识别器在全屏时不会触发 - MpMovieplayerController tap gesture recognizer doesn't trigger when in fullscreen 创建变量时,为什么点击手势识别器不起作用? - Why doesn't a tap gesture recognizer work when creating a variable? 表格视图单元格中UIView上的手势识别器 - Gesture Recognizer on UIView in Table View Cell 将手势识别器添加到表格单元格中的图像视图 - Adding a gesture recognizer to an image view in a table cell 自定义手势识别器无法正常运行 - Custom Gesture Recognizer doesn't work properly 手势识别器不适用于子视图 - gesture recognizer doesn't work on subview Swift:手势识别器未注册分路器 - Swift: Gesture Recognizer doesn't register Taps 当用户点击滚动视图以停止滚动时,将触发点击手势识别器 - Tap gesture recognizer gets triggered when user taps scroll view to stop scrolling longpress手势识别器不适用于地图视图上的用户位置(MKuserlocation) - iOS - longpress gesture recognizer doesn't work on user location (MKuserlocation) on map view - iOS 如果将轻按手势识别器添加到其背景视图,则不会调用iOS didSelectItemAtIndexPath - iOS didSelectItemAtIndexPath doesn't get called if a tap gesture recognizer is added to its background view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM