Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Animation Transition with Swift

Apple documentation (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html) have this sample:

CATransition* transition = [CATransition animation];
...

But when I did it in Swift:

    let transition = CATransition.animation()

I got an error "animation()' is unavailable: use object construction 'CAAnimation()'" - is this deprecated or? If yes, what's the new way of doing transition?

like image 322
Lim Thye Chean Avatar asked Aug 14 '14 02:08

Lim Thye Chean


1 Answers

In Objective-C [CAAnimation animation] is a convenience method for:

[[[CAAnimation alloc] init] autorelease]

CATransition inherits CAAnimation and therefore inherits the convenience constructor.

In Swift, this kind of initialization is gone, and you can create the CATransition object using the default constructor.

Try let transition = CATransition()

like image 58
Noah Witherspoon Avatar answered Oct 16 '22 08:10

Noah Witherspoon