I am developing an app where I use custom segues to navigate between two UIViewController
.
The segue to the second UIViewController
animates just fine. But when the unwind segue is triggered, the button that triggers it instantly disappears while slowly animating the rest just fine.
The Button is set up via Storyboard and I ctrl-dragged from it to the Exit of that UIViewController
. An unwind segue showed up and I set up all the necessary files.
I assign my custom class to the Unwind segue and now override the perform()
-method like so:
override func perform() {
let settingsVCView = self.sourceViewController.view
let startVCView = self.destinationViewController.view
let screenHeight = UIScreen.mainScreen().bounds.size.height
let screenWidth = UIScreen.mainScreen().bounds.size.width
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(startVCView, aboveSubview: settingsVCView)
UIView.animateWithDuration(0.8, delay: 0, options: .CurveEaseInOut, animations: { () -> Void in
settingsVCView.frame = CGRectMake(0, -(screenHeight), screenWidth, screenHeight)
startVCView.frame = CGRectMake(0, 0, screenWidth, screenHeight)
}) { (finished) -> Void in
self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)
}
}
Everything is set up and the animation is done like you can see in the gif. Some would say the animation works properly now, but the early disappearing of that button really bothers me. I tried:
dismissViewControllerAnimated:
functionI did not find any solution.
I finally got the issue resolved by first clearing all the layout constraints of that Button. I then tapped it again and it didn't disappear, so it had something to do with the constraints.
This is what the constraint should be set like.
The mistake was pinning the top constraint of the button to the Top Layout Guide and not the View top. Changing this anchor resolved my problem and my Button stopped hiding :)