私は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 {
}
}
ありがとう!
collectionView.isUserInteractionEnabledはおそらく、私の編集がより理にかなって...もう本当です。 – xcalysta