[英]Add a viewcontroller's view to the bottom of a collectionview to scroll?
[英]Scroll View is not disabled in CollectionView?
我是Swift的新手,正在尝试在collectionView中实现一项功能(启用了滚动。默认情况下,我希望启用滚动功能,而pangesturerecgonizer处于禁用状态。但是在识别出长按之后,滚动将会禁用并启用了平移手势。完成平移手势后,应将其禁用并启用滚动。我有以下代码。
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 {
}
}
谢谢!
我不明白,您是说触发平移时不能禁用滚动并且平移不再起作用吗?
尝试也为滚动视图添加用户交互:
collectionV.isScrollEnabled = false
collectionV.isUserInteractionEnabled = true
你可以申请
collectionView.isUserInteractionEnabled = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.