在swift(IOS)中以编程方式导航
作为一名Android开发者,我刚刚开始学习iOS开发。在安卓系统中,除了使用手势识别器,我发现在iOS中很难在任何视图上设置clicklistener。我想在视图上设置手势识别器,以便从一个视图控制器导航到另一个视图控制器。我能被引导吗在swift(IOS)中以编程方式导航,ios,objective-c,swift,mobile,segue,Ios,Objective C,Swift,Mobile,Segue,作为一名Android开发者,我刚刚开始学习iOS开发。在安卓系统中,除了使用手势识别器,我发现在iOS中很难在任何视图上设置clicklistener。我想在视图上设置手势识别器,以便从一个视图控制器导航到另一个视图控制器。我能被引导吗 override func viewDidLoad() { initiateTapGestures(view: circleView, action: #selector(self.tapDetectedForProfile))
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)
}
创建一个对象并将另一个推到此处
let profile = ProfileViewController()
self.navigationController?.pushViewController(ProfileViewController(), animated: false)
}
我收到错误原因:“无法在捆绑包中加载NIB:”NSBundleI收到错误原因:“无法在捆绑包中加载NIB:”NSBUNDLEW为此我们有UIButton。。。不要在iPhone中添加Tap手势,这是错误的做法。你有导航控制器吗?我们有UIButton用于此目的。。。不要在iPhone中添加Tap手势,这是错误的做法。你有导航控制器吗?谢谢。它的工作原理与我之前所做的一样,destinationProfileViewController显示一个黑色页面。将背景色设置为ProfileViewController视图。backgroundColor=.ViewDidLoad上的红色ProfileViewController已构建在情节提要上。我在其中有视图大多数情况下,当您没有将背景颜色设置为viewController时会发生这种情况,有时可能是约束问题。您可以添加故事板的屏幕截图来显示约束吗?我们已经能够用let nextVC=self.storyboard?来解决这个问题。实例化eviewcontrollerwhiteIdentifierStoryboardId为!ViewControllerHanks。它的工作原理与我之前所做的一样,destinationProfileViewController显示一个黑色页面。将背景色设置为ProfileViewController视图。backgroundColor=.ViewDidLoad上的红色ProfileViewController已构建在情节提要上。我在其中有视图大多数情况下,当您没有将背景颜色设置为viewController时会发生这种情况,有时可能是约束问题。您可以添加故事板的屏幕截图来显示约束吗?我们已经能够用let nextVC=self.storyboard?来解决这个问题。实例化eviewcontrollerwhiteIdentifierStoryboardId为!视图控制器
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
}