ios - 如何在 segue 期间访问 subview

标签 ios swift

我是 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/

相关文章:

ios - 将 NSMutableArray 传递给 UIView 类变为 nil

ios - 调试时 Xcode 崩溃

ios - 使用编码协议(protocol)解析 JSON nil 值

ios - 如何更改搜索栏中的边框和图标(Swift)

ios - 为什么在 shouldChangeCharactersIn 中返回 false 会覆盖 UITextField 中的旧文本?

ios - UIPageviewcontroller 过渡样式滚动连续

ios - 删除 UIActivityViewController 中的换行符

ios - 执行 segue 后标签栏消失

ios - 将 String 转换为 Int64 导致 32 位设备崩溃

ios - 单点触控 : load XIB asynchronously