以下是我的代码。我也发布了截图。Swift 3 - 无法执行功能
Button_CustomSegmentValueChanged是我自己制作的自定义分段控件。它是一个单独的按钮,工作正常,但我想从“SwipedRight”函数中运行“Button_CustomSegmentValueChanged”函数,但我无法传递正确的开关值以便这样做。需要帮助。
有人吗?
import UIKit
class CredentialsViewController: UIViewController {
@IBOutlet weak var loginView: UIView!
@IBOutlet weak var signupView: UIView!
var currentSelectedView = 0
override func viewDidLoad() {
super.viewDidLoad()
let swipeR = UISwipeGestureRecognizer(target: self, action: #selector(CredentialsViewController.SwipedRight(swipe:)))
swipeR.direction = .right
view.addGestureRecognizer(swipeR)
let swipeL = UISwipeGestureRecognizer(target: self, action: #selector(CredentialsViewController.SwipedLeft(swipe:)))
swipeL.direction = .left
view.addGestureRecognizer(swipeL)
//Hide view
signupView.transform = CGAffineTransform(translationX: signupView.frame.size.width, y: 0)
}
@IBAction func Button_CustomSegmentValueChanged(_ sender: CustomSegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
LoadLoginView()
break
case 1:
LoadSignupView()
break
default:
break
}
}
func SwipedRight(swipe : UISwipeGestureRecognizer){
if currentSelectedView == 1 {
Button_CustomSegmentValueChanged(0)
//LoadLoginView()
}
}
func SwipedLeft(swipe : UISwipeGestureRecognizer){
if currentSelectedView == 0 {
//LoadSignupView()
}
}
func LoadLoginView(){
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
self.signupView.transform = CGAffineTransform(translationX : self.loginView.frame.size.width, y : 0)
self.loginView.transform = .identity
self.currentSelectedView = 0
})
}
func LoadSignupView(){
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
self.signupView.transform = .identity
self.loginView.transform = CGAffineTransform(translationX: self.loginView.frame.size.width, y: 0)
self.currentSelectedView = 1
})
}
}
Screenshot of my code and error
Button_CustomSegmentValueChanged函数接受CustomSegmentedControl作为参数,你要发送诠释它 – 3stud1ant3
您好,我知道你在说什么,但你能告诉我它是如何做正确的代码。问题是我已经制作了一个具有两个选项的自定义分段控制器,并且我使用两个视图在两个视图之间切换。当我点击分段控件时,一切正常。当我滑动,它的工作正常,但分段控制器中的选择器没有改变。原因在于它需要用来了解开关。我想通过从另一个函数调用我的tapped函数来复制它,只是让它工作。看看视频http://youtu.be/Z5CHq4-MeVo – Biks
好吧,你可以显示CustomSegmentedControl的代码? – 3stud1ant3