-
Notifications
You must be signed in to change notification settings - Fork 536
How Do I enable Tap Anywhere in the view to Dismiss ? #205
Comments
Yeah this is a big issue in this , but i have resolved by For iOS below 13 - In AppDelegate - var topWindow: CustomWindow? In didfinishLaunching - topWindow = CustomWindow(frame: UIScreen.main.bounds) After this create a util class - class CustomWindow: UIWindow{ Then call this observer in my class where i have to dismiss the tooltip. NotificationCenter.default.addObserver(self, selector: #selector(self.dismisstooltip(notification:)), name: Notification.Name(rawValue: "eventTouch"), object: nil) For iOS 13 and above In Scene Delegate connectionoption - let tapGesture = UITapGestureRecognizer(target: self, action: nil) func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { and Use this observer same as above. |
@Vidhanshu09 can you give an working example project |
Did anyone find any working solution? |
You can subclass the Easytipview and add that functionality. Note: make sure to call the show function you're using. import EasyTipView
class DismissibleEasyTipView: EasyTipView {
lazy var tapRecognizer: UITapGestureRecognizer = {
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.didTapOnScreen))
tapRecognizer.numberOfTapsRequired = 1
return tapRecognizer
}()
lazy var dismissView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.frame = UIScreen.main.bounds
return view
}()
func show(on view: UIView) {
self.show(forView: view)
guard let superView = self.superview else { return }
self.addDismissView(on: superView)
}
private func addDismissView(on superView: UIView) {
if self.dismissView.superview == nil {
superView.addSubview(self.dismissView)
}
if !(self.dismissView.gestureRecognizers ?? []).contains(self.tapRecognizer) {
self.dismissView.addGestureRecognizer(self.tapRecognizer)
}
self.tapRecognizer.isEnabled = true
}
func hide() {
self.dismissView.removeFromSuperview()
self.tapRecognizer.isEnabled = false
self.dismiss()
}
@objc func didTapOnScreen() {
self.hide()
}
} Use DismissableEasyTipView from now on and use |
There should be an option to enable tap anywhere in the view to dismiss the tooltip. That's how tooltips should work, currently only tapping inside the tool tip view dismisses it, if I wanna show multiple tooltips use has to tap on each of them to dismiss which is not at all user friendly.
The text was updated successfully, but these errors were encountered: