2016-09-07 3 views
0

Wie kann ich UIView.animateWithDuration im Swift-Protokoll verwenden? Wenn ich versuche, es zu benutzen, habe ich immer:Verwenden Sie UIView.animateWithDuration innerhalb des Protokolls

mehrdeutige Verweis auf Mitglied 'animateWithDuration (_: Verzögerung: Optionen: Animationen: Abschluss :)

Wie kann ich Bezug auf UIView erhalten (animateWithDuration ist statische Methode, wie ich verstehe)?

+0

Bitte zeigen Sie uns Ihren Code – Hamish

Antwort

1

Da Sie keine Implementierung innerhalb der Protokolldeklaration selbst bereitstellen können, sollten Sie innerhalb der Standardimplementierung auf UIView Klasse verweisen. Ich hoffe, dass einer dieser drei Vorlagenkästen genau das ist, was Sie brauchen:

import UIKit 

protocol SomeProtocol { 
    static func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) 
    func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) 
    func someCustomFuncForAnimate() 
} 

extension SomeProtocol { 
    static func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) { 
     UIView.animateWithDuration(duration, delay: delay, options: options, animations: animations, completion: completion) 
    } 
    func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) { 
     UIView.animateWithDuration(duration, delay: delay, options: options, animations: animations, completion: completion) 
    } 
    func someCustomFuncForAnimate() { 
     UIView.animateWithDuration(0.2, delay: 1, options: .TransitionCrossDissolve, animations: {/*...*/}, completion: nil) 
    } 
} 
Verwandte Themen