Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1217 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add tap gesture to UIStackView

#1
Im attempting to add a `UITapGesture` to a `UIStackView` within a collectionView cell but each time I do my app crashes. (All `IBOutlets` are connected) This there something I'm doing wrong here?

let fGuesture = UITapGestureRecognizer(target: self, action: #selector(self.showF(_:)))
cell.fstackView.addGestureRecognizer(fGuesture)

func showF(sender: AnyObject){
print(111)
}
Reply

#2
I had UIButtons as subviews, so even if I added gesture to UIStackView, it ignored my gesture.

So I added the code
```
button.isUserInteractionEnabled = false
```
to make UIStackView receive my touch.
Reply

#3
Set the gesture recognizer in the main thread:

```swift
DispatchQueue.main.async {
self.view.gestureRecognizers = [self.tapGestureRecognizer]
}
```
Reply

#4
Is the stackview enabled for touch ?
Try to set Userinteraction Parameter

cell.fstackView.isUserInteractionEnabled = true
Reply

#5
If the app is crashing due to `fatal error: unexpectedly found nil while unwrapping an Optional value` - you may need to add some delay before adding the gesture recognizer to the stack view.

If you are accessing the stack view property in the collection view cell subclass's init or in the collection view's delegate methods, the stack view may not have been initialized yet. Try using a timer or GCD to add a 0.1 second delay and it should work fine...

Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(prepareStackView), userInfo: nil, repeats: false)

...

@objc func prepareStackView() {
let tap = UITapGestureRecognizer(target: self, action: #selector(stackViewTapped))
myStackView.addGestureRecognizer(tap)
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through