【问题标题】:Setting options in animateWithDuration in Swift 2在 Swift 2 中的 animateWithDuration 中设置选项
【发布时间】:2015-07-21 13:21:39
【问题描述】:

我正在使用以下代码为文本字段设置动画:

UIView.animateWithDuration(0.5, delay: 0.4,
        options: .Repeat | .Autoreverse | .CurveEaseOut, animations: {
            self.password.center.x += self.view.bounds.width
        }, completion: nil)

我收到错误Could not find member 'Repeat'

代码只有在我只设置一个选项时才有效。 为什么不让我设置多个选项?

【问题讨论】:

    标签: uiview swift2 animatewithduration


    【解决方案1】:

    组合OptionSetType的语法已经改变,你可以这样做:

    UIView.animateWithDuration(0.5, delay: 0.4,
        options: [.Repeat, .CurveEaseOut, .Autoreverse], animations: {
            self.password.center.x += self.view.bounds.width
        }, completion: nil)
    

    【讨论】:

    • 非常感谢!你在哪里找到的?
    • UIViewAnimationOptions 的文档表明它符合OptionSetType 协议。 OptionSetType 的文档有一个关于如何组合选项的非常好的示例。您也可以在 Xcode 中按命令单击 UIViewAnimationOptions,然后按 cmd 并单击 OptionSetType 以查看与文档相同的示例代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 2017-09-16
    • 2016-02-18
    • 2013-03-28
    • 2019-07-01
    • 1970-01-01
    相关资源
    最近更新 更多