【问题标题】:Custome UIView behaves than actual UIView自定义 UIView 的行为比实际的 UIView
【发布时间】:2015-03-12 10:16:39
【问题描述】:

我在情节提要中创建了自定义 UIView 类说“XXX”。我在视图控制器中创建了对象。对象名称是“YYY”。现在我正在尝试调用 animateWithDiruation 方法。

 @IBOutlet var YYY: XXX!

    YYY.animateWithDuration(1.0, animations: { () -> Void in
        //changes to animate
    })

它抛出错误。 XXX 没有名为 animateWithDuration 的成员。

但是下面的代码可以正常工作。

UIView.animateWithDuration(1.0, animations: { () -> Void in
    //changes to animate
})

如何使用自定义 UIView 类调用 animateWithDuration 方法?

谢谢

【问题讨论】:

    标签: ios swift animation uiview


    【解决方案1】:

    animateWithDuration 是您在 UIView 类上运行的静态(类)方法。

    您应该使用UIView.animateWithDuration 为您的 YYY 自定义视图设置动画,例如:

    UIView.animateWithDuration(1.0, animations: { () -> Void in
        //changes to animate
        XXX.center = CGPoint(x: 10, y: 20)
    })
    

    【讨论】:

      【解决方案2】:

      如果您查看文档,您会发现 animateWithDuration 是一个类方法。这意味着,您只能使用 UIView.animateWithDuration ....

      访问它

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多