2017-08-02 10 views
0

私はswiftに新しく、collectionViewに機能を実装しようとしています(デフォルトでは、スクロールを有効にし、pangesturerecgonizerを無効にします)。私は、次のコードを持っています。パンジェスチャーが行われた後、それを無効にする必要があり、スクロールを有効にする必要があります。無効とパンジェスチャーを有効にすることでしょう。Scroll ViewはCollectionViewで無効になっていませんか?

lazy var panGesture: UIPanGestureRecognizer = { 
    let pan = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan(sender:))) 
     pan.delegate = self 
    return pan 
}() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    collectionView.delegate = self 
    collectionView.dataSource = self 
    collectionView.backgroundColor = UIColor.cyan 
    self.view.addSubview(collectionView) 

    self.view.addConstraint(NSLayoutConstraint(item: collectionView, attribute: .height, relatedBy: .equal, toItem: self.view, attribute: .height, multiplier: 1.0, constant: 0.0)) 

    collectionView.translatesAutoresizingMaskIntoConstraints = false 
    collectionView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true 
    collectionView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true 
    collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true 
    collectionView.addGestureRecognizer(panGesture) 
    panGesture.isEnabled = false 

    let tap = UILongPressGestureRecognizer(target: self, action: #selector(self.handleTap(sender:))) 
    tap.delegate = self 
    collectionView.addGestureRecognizer(tap) 

} 

func handlePan(sender: UIPanGestureRecognizer? = nil) { 
    var locationOfBeganTap: CGPoint? 

    if sender?.state == .possible { 
    } 

    if sender?.state == .ended { 
     startTime = NSDate.timeIntervalSinceReferenceDate 
    } 
} 

func handleTap(sender: UIPanGestureRecognizer? = nil){    
    if sender?.state == .began { 
     panGesture.isEnabled = true 
     self.collectionView!.isScrollEnabled = false 
    } 

    if sender?.state == .ended { 
    } 
} 

ありがとう!

答えて

1

私はしないでくださいパンが作動したときにスクロールを無効にすることはできず、パンはもはや機能しないと言っていますか?

また、スクロールビューのためのユーザインタラクションを追加する

試してみてください。

collectionV.isScrollEnabled = false 
collectionV.isUserInteractionEnabled = true 
+0

collectionView.isUserInteractionEnabledはおそらく、私の編集がより理にかなって...もう本当です。 – xcalysta

0

あなただけ適用することができますが、

collectionView.isUserInteractionEnabled = true

関連する問題