Reputation: 2528
I am just picking up iOS development as an Android developer. In Android it is possible to set clicklistener on any view which I find difficult in iOS except with Gesture Recognizer. I want to set the gesture recognizer on a view to navigate from one view controller to another. Can I be guided
override func viewDidLoad() {
initiateTapGestures(view: circleView, action: #selector(self.tapDetectedForProfile))
}
func initiateTapGestures(view:UIView, action:Selector?){
let singleTap = UITapGestureRecognizer(target: self, action: action)
view.isUserInteractionEnabled = true
view.addGestureRecognizer(singleTap)
}
@objc func tapDetectedForProfile(){
print("profile setting")
let profile = ProfileViewController()
self.navigationController?.pushViewController(ProfileViewController(), animated: false)
}
Upvotes: 1
Views: 74
Reputation: 100549
You create an object and push another one here
let profile = ProfileViewController()
self.navigationController?.pushViewController(ProfileViewController(), animated: false)
}
Upvotes: 1
Reputation: 4466
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapDetectedForProfile))
//tapGesture.numberOfTapsRequired = 2 //Default is 1 no need to mention //2 Double tab //3...
//tapGesture.numberOfTouchesRequired = 2 // Default is 1. The number of fingers required to match
circleView.addGestureRecognizer(tapGesture)
}
@objc func tapDetectedForProfile() {
print("Tabbed")
// do something
// Navigation
}
Upvotes: 1
Reputation: 2698
override func viewDidLoad() {
super.viewDidLoad()
circle.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didClickedView(_ :))))
}
@objc func didClickedView(_ sender : UITapGestureRecognizer){
print("profile setting")
let profile = ProfileViewController()
self.navigationController?.pushViewController(ProfileViewController(), animated: false)
}
Upvotes: 1