尝试自定义动画时符合UIViewControllerAnimatedTransitioning协议时出错

时间:2015-04-20 11:47:45

标签: swift storyboard xcode6 uiviewanimation xcode6.3

我一直在线阅读有关创建自定义动画的教程。因此,为了制作自定义动画,我创建了一个类型为NSObject的类名称Transition Manager。我面临两个问题,

1)因此,当进一步将类定义为

class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning, 
UIViewControllerTransitioningDelegate
{
    //Further Code
}

我收到编译时错误,

Type 'TransitionManager' does not conform to protocol 
'UIViewControllerAnimatedTransitioning'

Protocol requires function 'transitionDuration' with type 
'(UIViewControllerContextTransitioning) -> NSTimeInterval'

以下是“过渡期”'功能:

// return how many seconds the transition animation will take
func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval
{
    return 0.5
}

2)弹出另一个编译时错误,位于以下行:

  // get the duration of the animation

    let duration = self.transitionDuration(transitionContext)

错误:

  'TransitionManager' does not have a member named 'transitionDuration'

这是完整的TransitionManager.swift:http://pastebin.com/LkLym5Ci

1 个答案:

答案 0 :(得分:2)

您的transitionDuration方法目前类之外,如PasteBin所示。

这就是为什么你收到一条错误消息,说transitionDuration不是班级的成员。

如果您将transitionDuration方法放在 TransitionManager类中,则错误将消失。