2017-07-27 132 views
0

我安裝了一個吊艙Material和莢有這樣的事情:覆蓋符合協議斯威夫特

extension UIViewController: UIViewControllerTransitioningDelegate { 
    //here is the method to conform protocol 
} 

但我需要我自己的貼合在同一個地方的協議:

當我嘗試致以UIViewControllerUIViewControllerTransitioningDelegate然後我得到了一個錯誤:

redundant conformance to protocol.

我需要做什麼?

extension UIViewController: UIViewControllerTransitioningDelegate { 
    //my OWN implementation here I need 
} 

有沒有辦法來覆蓋與我自己的Pod的一致性?

+0

您的超類已經確認了協議 –

+0

它是不是問題的答案:)對不起 –

+2

如果該類已經實現了,則不需要將該協議添加到該擴展中。你不能在一個擴展中重寫一個方法,你最好的選擇是繼承Pod類並覆蓋子類中的方法 – DatForis

回答

0

我發現,工作的唯一方法是創建一個單獨的BaseController類,這只是一個UIViewController

import UIKit 
class BaseController: UIViewController { 

} 

的子類,被放置在單獨的文件不導入材料。 所有你想重寫UIViewControllerTransitioningDelegate的UIViewControllers都應該是它的一個子類。

import UIKit 
import Material 
class ViewController: BaseController { 

} 

這將使編譯

extension ViewController: UIViewControllerTransitioningDelegate{ 
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return nil 
    } 
} 

它不是最優化的解決方案,但它的工作原理

編輯:這將允許您使用的材質元素,如文本字段和這種同時具有您保留UIViewController的默認功能,而不需要在庫中找到添加項