我的segue走得太远了

时间:2017-07-04 21:11:50

标签: ios swift

This is how my story board currently looks

当我单击垂直放置按钮的视图上的按钮时,我可以打开正确的相应视图,但是,当我放松回来时,我最终会一直回到登录页面,而不是页面按钮。我在正确的地方放松了,只是不知道为什么它会走得那么远。

这是带有按钮

的视图控制器的代码
@IBOutlet weak var menuButton: UIButton!

@IBOutlet weak var clubButton: UIButton!

@IBOutlet weak var announcemnetsButton: UIButton!

@IBOutlet weak var eventButton: UIButton!

var transition = QZCircleSegue()


override func viewDidLoad() {
    super.viewDidLoad()

    menuButton.layer.cornerRadius = menuButton.frame.size.width / 2
    clubButton.layer.cornerRadius = menuButton.frame.size.width / 2
    announcemnetsButton.layer.cornerRadius = menuButton.frame.size.width / 2
    eventButton.layer.cornerRadius = menuButton.frame.size.width / 2

    menuButton.layer.masksToBounds = true
    clubButton.layer.masksToBounds = true
    announcemnetsButton.layer.masksToBounds = true
    eventButton.layer.masksToBounds = true

}
override var prefersStatusBarHidden : Bool {
    return true;

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "NewVC") {
        self.transition.animationChild = menuButton
        self.transition.animationColor = UIColor(red: 255/255, green: 0/255, blue: 0/255, alpha: 1.0)
    } else if (segue.identifier == "ClubVC") {
        self.transition.animationChild = clubButton
        self.transition.animationColor = UIColor(red: 81/255, green: 172/255, blue: 246/255, alpha: 1.0)
    } else if (segue.identifier == "AnnouncementVC") {
        self.transition.animationChild = announcemnetsButton
        self.transition.animationColor = UIColor(red: 255/255, green: 179/255, blue: 109/255, alpha: 1.0)
    } else if segue.identifier == "EventVC" {
        self.transition.animationChild = eventButton
        self.transition.animationColor = UIColor(red: 63/255, green: 255/255, blue: 176/255, alpha: 1.0)
    }
    let toViewController = segue.destination as! NewViewController
    /* Set both, the origin and destination to your transition manager*/
    self.transition.fromViewController = self
    self.transition.toViewController = toViewController
    /* Add the transition manager to your transitioningDelegate View Controller*/
    toViewController.transitioningDelegate = transition
}

/* Specify the destination view controller to enable the unwind segue*/
@IBAction func unwindToMainViewController (sender: UIStoryboardSegue){
    self.dismiss(animated: true, completion: nil)

} }

1 个答案:

答案 0 :(得分:1)

iOS所做的评论是对的。仅仅因为你使用segue进入视图控制器并不意味着你必须使用一个离开。假设您想要回到刚刚显示的视图控制器,有几种可能性。你想要做的是将当前视图控制器从堆栈中弹出。如果您正在使用导航控制器(很可能是您),那么这是如何做到的:

 self.navigationController?.dismiss(animated: true, completion: nil)

您可以将其简化为:

 dismiss(animated: true, completion: nil)

因为视图控制器有一个self.dismiss()方法。试一试,让我知道这是否适合您。