Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

ios - UITapGestureRecognizer Dismiss keyboard & UICollectionView conflict

I have a UIScrollView with numerous stack subviews.

I have a UITapGestureRecognizer that dismisses the keyboard and this works.

let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKbd))
self.view.addGestureRecognizer(tap)

One of my subviews is a stack view that holds a collection view.

stackView = UIStackView()
scrollView.addSubview(stackView)
stackView.axis = .horizontal
stackView.anchor(top: notesTextView.bottomAnchor, left: scrollView.leftAnchor, bottom: scrollView.bottomAnchor, right: scrollView.rightAnchor, paddingTop: 8, paddingLeft: 2, paddingBottom: 2, paddingRight: 2, height: 400)
let child = ImageGalleryViewController()
stackView.addArrangedSubview(child.view)
child.didMove(toParent: self)

Problem:

This results in:

  1. Keyboard will dismiss when screen tapped
  2. didSelectItemAt only works when two fingers are used on a cell

I assume this is to do with a conflict of gesture recognizers.

I would appreciate any guidance on how to make this work. I assume it's to do with the focus of the gesture recognizers?

question from:https://stackoverflow.com/questions/65859275/uitapgesturerecognizer-dismiss-keyboard-uicollectionview-conflict

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you can handle dismiss keyboard when scollView scrolled or offsetY is a constant number. you never need to dismiss the keyboard with gestures.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...