我是 iOS 编程的新手,我正在尝试制作一个简单的 segue,其中源 View 和目标 View 的 subview 都是动画的。
我无法在我的 segue 类中访问我的源 View 上的 subview 来为它们设置动画。在 segue 期间访问和动画化源 View 的 subview 的最简单方法是什么?
这是我的代码的简化版本。
// Source view controller
class ViewController: UIViewController {
@IBOutlet weak var myButton: UIButton!
// other normal view controller code
}
class mySegue: UIStoryboardSegue {
override func perform() {
UIView.animate(withDuration: 1.0, animations: {
// how do I access and animate myButton?
// source.myButton
})
}
}
最佳答案
您可以使用此代码:
class MySegue: UIStoryboardSegue {
override func perform() {
UIView.animate(withDuration: 1.0, animations: {
let sourceController = self.source as! ViewController
sourceController.myButton
})
}
}
关于ios - 如何在 segue 期间访问 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41771793/