swift - 尝试自定义动画时遵守 UIViewControllerAnimatedTransitioning 协议(protocol)时出错

标签 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'

这是“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 方法目前在类之外,如PasteBin 中所示。

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

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

关于swift - 尝试自定义动画时遵守 UIViewControllerAnimatedTransitioning 协议(protocol)时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29747037/

相关文章:

ios - 自定义 Segue 动画不工作

ios - 将GPX文件添加到Xcode 6项目

ios - 使用自动布局的 IB_DESIGNABLE 自定义 View 的错位 View 警告和奇怪行为

ios - 使用 swift 添加多个文本字段到 firebase

ios - DispatchQueue.global(qos : . default) 在后台或锁屏时继续,如何暂停?

ios - 基于 customObject 属性订购 Collection View 单元格 - Swift 4 -Xcode 9

swift - 在带有继承的Swift 4中使用Decodable

ios - Swift 多 Storyboard - 如何访问特定的 Storyboard

ios - 难以理解 Obj-C MVC : exit and unwindSegue

xcode6 - Xcode 6 重构 : Can only refactor C and Objective C code