【问题标题】:Strange UIView.animateWithDuration compilation error if have some code in animations block如果动画块中有一些代码,则奇怪的 UIView.animateWithDuration 编译错误
【发布时间】:2015-08-12 21:27:27
【问题描述】:

我有代码

UIView.animateWithDuration(0.5, delay: 0.4, options: .Repeat, animations: { // self.circle.center += 10 }, completion: nil) }

编译。 但是如果我取消注释行 self.circle.center += 10 我会有 ViewController.swift:28:23: 找不到成员“重复”。

self.circle 是 @IBOutlet var circle: Circle! 连接到 Main.storyboard 上的某个对象。 Circle 是使用自定义 drawRect 扩展 UIView 的类。

所有这些东西有什么问题?

【问题讨论】:

  • center 是 CGPoint 所以你不能 += 10,你需要增加它的 x 或 y 属性

标签: ios swift uiview xcode6 animatewithduration


【解决方案1】:

要将+10 添加到中心点,您需要执行以下操作:

self.circle.center.x += 10
self.circle.center.y += 10

中心属性是一个CGPoint,包含一个xy 值。因此,将+10 单独添加到中心并没有什么意义。

struct CGPoint {
    var x: CGFloat
    var y: CGFloat
}

【讨论】:

  • 老实说我不知道​​。由于这个原因,目前我仍然更喜欢使用 Objective-C。 Swift 仍然是新的,在 Xcode 中会出现奇怪的错误。
猜你喜欢
  • 2023-04-01
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-25
相关资源
最近更新 更多