【问题标题】:Tap is not detected on continuous scrolling of UICollectionView iOS?连续滚动 UICollectionView iOS 时未检测到点击?
【发布时间】:2016-08-08 14:09:22
【问题描述】:

我有一个使用 NSTimer 连续滚动的 UICollectionView,这里是代码

let timer = NSTimer(timeInterval: 0.1, target: self, selector: #selector(HomeViewController.scrollToNextCard), userInfo: nil, repeats: true)
NSRunLoop.currentRunLoop().addTimer(timer!, forMode: NSDefaultRunLoopMode)

func scrollToNextCard(){
    UIView.animateWithDuration(0.1, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                // I am changing the contentOffset of collectionview for continuous scrolling
        }, completion: {(finished:Bool) in

    })

在滚动过程中点击任何可见单元格时,委托的方法 didSelectItemAtIndexpath 不会被调用。如何在保持集合视图滚动的同时实现点击检测。请帮忙谢谢

【问题讨论】:

  • 试试NSRunLoopCommonModes 而不是NSDefaultRunLoopMode
  • 不,那不行。

标签: ios uiscrollview uicollectionview uigesturerecognizer


【解决方案1】:

我找到了相同的答案,我必须在动画块上添加 AllowUserInteraction 标志,如代码所示:

func scrollToNextCard(){
   UIView.animateWithDuration(Constants.CardFlowTimeInterval, delay: 0.0, options: [.CurveEaseInOut,.AllowUserInteraction], animations: {
        }, completion: {(finished:Bool) in
   })
}

【讨论】:

    猜你喜欢
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    相关资源
    最近更新 更多