简体   繁体   中英

cannot find protocol declaration for 'CAAnimationDelegate'

My code was fine before, but it tips me :

cannot find protocol declaration for 'CAAnimationDelegate';did you mean 'UIApplicationDelegate'?

when I run it today.

I have tried import QuartzCore/CAAnimation.h but doesn't work.

CAAnimationDelegate is a new protocol that was added in the iOS 10 SDK. That means it is there if you build with Xcode 8, but not there if you build with Xcode 7.

When you build with Xcode 8, you'll get a warning to say:

Assigning to 'id<CAAnimationDelegate> _Nullable' from incompatible type 'WhateverUIViewController *const __strong'

If you add the CAAnimationDelegate, your code won't build in Xcode 7 anymore. If you need to build with both Xcode's, you need to use ifdefs:

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 100000
// CAAnimationDelegate is not available before iOS 10 SDK
@interface WhateverUIViewController ()
#else
@interface WhateverUIViewController () <CAAnimationDelegate>
#endif

CAAnimationDelegate is not a protocol. There is no need to tell your class is going to implement the CAAnimationDelegate .

First you need to import QuartzCore/QuartzCore.h .Then, You just pass your class's (in which you want to implement the animation delegate methods) object as delegate to your CAAnimation object. It will automatically calls animationDidStart while starting the animation and calls animationDidStop method while finishing the animation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM