我正在用Swift創建iOS應用程序。我發現了一個我想在我的表格視圖中實現的動畫,但代碼位於Objective-C中。無法符合Swift中的obj-c協議
庫:https://github.com/recruit-mp/RMPZoomTransitionAnimator
我已經成功過渡的OBJ-C代碼來斯威夫特,但似乎不符合所需的協議。
協議:
@protocol RMPZoomTransitionAnimating <NSObject>
@required
- (UIImageView *)transitionSourceImageView;
- (UIColor *)transitionSourceBackgroundColor;
- (CGRect)transitionDestinationImageViewFrame;
@end
我迅速實施:
實現該協議第一類:
class ChallengeViewController: UIViewController, RMPZoomTransitionAnimating
func transitionSourceImageView() -> UIImageView {
return imageView
}
func transitionSourceBackgroundColor() -> UIColor {
return UIColor.whiteColor()
}
func transitionDestinationImageViewFrame() -> CGRect {
return imageView.frame
}
第二類:
class ChallengeTableViewController: UITableViewController, RMPZoomTransitionAnimating
func transitionSourceImageView() -> UIImageView {
return imageForTransition!
}
func transitionSourceBackgroundColor() -> UIColor {
return UIColor.whiteColor()
}
func transitionDestinationImageViewFrame() -> CGRect {
return imageFrame!
}
此檢查時發生總是動畫之前失敗:
Protocol *animating = @protocol(RMPZoomTransitionAnimating);
BOOL doesNotConfirmProtocol = ![self.sourceTransition conformsToProtocol:animating] || ![self.destinationTransition conformsToProtocol:animating];
我讀過這個話題How to create class methods that conform to a protocol shared between Swift and Objective-C?,但沒有發現任何幫助
任何線索將自己非常感激
有一個'sourceTransition'和'destinationTransition'。他們是兩個不同的對象。他們必須_符合RMPZoomTransitionAnimating。但是您只顯示符合RMPZoomTransitionAnimating的_one_對象。另一個呢? – matt
[如何創建符合在Swift和Objective-C之間共享的協議的類方法]可能的重複(http://stackoverflow.com/questions/29399871/how-to-create-class-methods-that-conform -i-protocol-shared-between-swift-and) – Jeef
@Jeef我現在來看看它 – Mindaugas