为什么触发 unwind segue 的按钮会立即消失?
Why is the button that triggers an unwind segue instantly disappearing?
我正在开发一个应用程序,我在其中使用自定义 segues 在两个 UIViewController
之间导航。
第二个 UIViewController
的转场动画效果很好。但是当触发 unwind segue 时,触发它的按钮会立即消失,同时慢慢地为其余部分设置动画。
Button 是通过 Storyboard 设置的,我按住 ctrl 键从它拖动到那个 UIViewController
的 Exit。一个展开的转场出现了,我设置了所有必要的文件。
我将我的自定义 class 分配给 Unwind 转场,现在重写 perform()
方法,如下所示:
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)
}
}
一切都已设置好,动画已完成,就像您在 gif 中看到的那样。有人会说动画现在可以正常工作,但那个按钮的早期消失真的让我很困扰。我试过了:
- 调整按钮高亮状态
- 不仅在 Compact/Regular
中安装按钮
- 将按钮类型从系统设置为自定义
- 试图追踪确切的时刻,按钮通过断点消失(找不到,但发现在闭包块中设置框架也不是问题)
- 注释掉
dismissViewControllerAnimated:
函数
我没有找到任何解决方案。
我终于通过首先清除该按钮的所有布局约束解决了问题。然后我又点了一下它并没有消失,所以它与约束有关。
This is what the constraint should be set like.
错误是将按钮的顶部约束固定到顶部布局指南而不是视图顶部。更改此锚点解决了我的问题,我的按钮不再隐藏 :)
我正在开发一个应用程序,我在其中使用自定义 segues 在两个 UIViewController
之间导航。
第二个 UIViewController
的转场动画效果很好。但是当触发 unwind segue 时,触发它的按钮会立即消失,同时慢慢地为其余部分设置动画。
Button 是通过 Storyboard 设置的,我按住 ctrl 键从它拖动到那个 UIViewController
的 Exit。一个展开的转场出现了,我设置了所有必要的文件。
我将我的自定义 class 分配给 Unwind 转场,现在重写 perform()
方法,如下所示:
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)
}
}
一切都已设置好,动画已完成,就像您在 gif 中看到的那样。有人会说动画现在可以正常工作,但那个按钮的早期消失真的让我很困扰。我试过了:
- 调整按钮高亮状态
- 不仅在 Compact/Regular 中安装按钮
- 将按钮类型从系统设置为自定义
- 试图追踪确切的时刻,按钮通过断点消失(找不到,但发现在闭包块中设置框架也不是问题)
- 注释掉
dismissViewControllerAnimated:
函数
我没有找到任何解决方案。
我终于通过首先清除该按钮的所有布局约束解决了问题。然后我又点了一下它并没有消失,所以它与约束有关。
This is what the constraint should be set like.
错误是将按钮的顶部约束固定到顶部布局指南而不是视图顶部。更改此锚点解决了我的问题,我的按钮不再隐藏 :)