gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:35:06 25 4
gpt4 key购买 nike

作为一名 Android 开发人员,我刚刚开始着手 iOS 开发。在 Android 中,除了 Gesture Recognizer 之外,可以在 iOS 中发现困难的任何 View 上设置 clicklistener。我想在 View 上设置手势识别器以从一个 View Controller 导航到另一个 View Controller 。我可以被引导吗

    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)

}

最佳答案

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

关于ios - 在 swift (IOS) 中以编程方式导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60813739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com