尝试自定义动画时遵守 UIViewControllerAnimatedTransitioning 协议时出错

Error in conforming with UIViewControllerAnimatedTransitioning protocol while trying Custom Animations

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

1) 所以当进一步定义 class 为时,

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

我遇到编译时错误,

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

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

这里是 'transitionDuration' 函数:

// 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

您的 transitionDuration 方法当前 之外 class,如 PasteBin 中所示。

这就是为什么您会收到一条错误消息,指出 transitionDuration 不是 class 的成员。

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