【问题标题】:iOS - Type 'UIView' has no member 'AnimationOptions'iOS - 类型“UIView”没有成员“AnimationOptions”
【发布时间】:2018-09-29 03:21:59
【问题描述】:

我正在使用 TextFieldEffects 在我的文本字段中添加文本输入效果。它显示错误

类型“UIView”没有成员“AnimationOptions”

这是代码。

override open func animateViewsForTextEntry() {
    borderLayer.frame.origin = CGPoint(x: 0, y: font!.lineHeight)

    UIView.animate(withDuration: 0.2, delay: 0.3, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.0, options: UIView.AnimationOptions.beginFromCurrentState, animations: ({

        self.placeholderLabel.frame.origin = CGPoint(x: self.placeholderInsets.x, y: self.borderLayer.frame.origin.y - self.placeholderLabel.bounds.height)
        self.borderLayer.frame = self.rectForBorder(self.borderThickness, isFilled: true)

    }), completion: { _ in
        self.animationCompletionHandler?(.textEntry)
    })
}

override open func animateViewsForTextDisplay() {
    if text!.isEmpty {
        UIView.animate(withDuration: 0.35, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: UIView.AnimationOptions.beginFromCurrentState, animations: ({
            self.layoutPlaceholderInTextRect()
            self.placeholderLabel.alpha = 1
        }), completion: { _ in
            self.animationCompletionHandler?(.textDisplay)
        })

        borderLayer.frame = rectForBorder(borderThickness, isFilled: false)
    }
}

这是错误的屏幕截图。

如何解决这个问题?

【问题讨论】:

  • UIView.AnimationOptions.beginFromCurrentState 在 Swift 4.2 (Xcode 10) 中编译没有问题。您使用的是旧版本吗?
  • 我使用的是 Xcode 9 和 Swift 4.0
  • 这和你上一个问题stackoverflow.com/q/52523952/1187415的问题一样:你尝试用Xcode 9编译Swift 4.2代码。

标签: ios swift xcode uitextfield


【解决方案1】:

它应该是UIViewAnimationOptions.beginFromCurrentState,至少在 Xcode

【讨论】:

  • 通常编译器足够智能来推断类型,因此您可以使用. beginFromCurrentState 并跳过前缀。 (这在 Xcode 9.x 和 10.x 中具有相同的优点。)
【解决方案2】:

尝试将UIView.AnimationOptions.beginFromCurrentState 更改为[.beginFromCurrentState]

【讨论】:

  • 如果您只提供一个标志,则不需要大括号。在这种情况下,[.beginFromCurrentState].beginFromCurrentState 可以互换。
猜你喜欢
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 2016-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多