在 swift(IOS) 中以编程方式导航

Navigating programmatically in swift(IOS)

作为 Android 开发人员,我刚刚开始 iOS 开发。在 Android 中,可以在我认为在 iOS 中很难设置的任何视图上设置 clicklistener,除了 Gesture Recognizer。我想在视图上设置手势识别器以从一个视图控制器导航到另一个视图控制器。可以指导吗

    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)

    }

您创建一个对象并将另一个对象推送到此处

    let profile = ProfileViewController()
    self.navigationController?.pushViewController(ProfileViewController(), animated: false)

}
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)
}
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
}