#import "AppDelegate.h"
@interface AppDelegate ()
<
CAAnimationDelegate
>
@property (nonatomic, strong) CALayer *mask;
@property (nonatomic, strong) UIImageView *imageView;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.imageView = [[UIImageView alloc]initWithFrame:self.window.frame];
self.imageView.image = [UIImage imageNamed:@"twitterScreen"];
[self.window addSubview:self.imageView];
//初始化mask
self.mask = [CALayer layer];
self.mask.contents = (__bridge id _Nullable)([UIImage imageNamed:@"twitterBird"].CGImage);
self.mask.position = self.window.center;
self.mask.bounds = CGRectMake(0, 0, 100, 80);
self.imageView.layer.mask = self.mask;
[self creawteBaseAnimateMask];
self.window.rootViewController = [[UIViewController alloc]init];
self.window.backgroundColor = [UIColor colorWithRed:70/255.f green:154/255.f blue:233/255.f alpha:1];
[self.window makeKeyAndVisible];
[UIApplication sharedApplication].statusBarHidden = YES;
return YES;
}
/**
添加动画
*/
- (void)creawteBaseAnimateMask {
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"bounds"];
key.duration = 1;
key.delegate = self;
key.beginTime = CACurrentMediaTime() + 1;
NSValue *initalBounds = [NSValue valueWithCGRect:self.mask.bounds];
NSValue *secondBounds = [NSValue valueWithCGRect:CGRectMake(0, 0, 80, 64)];
NSValue *finalBounds = [NSValue valueWithCGRect:CGRectMake(0, 0, 2000, 2000)];
key.values = @[initalBounds,secondBounds,finalBounds];
key.keyTimes = @[@0, @0.3, @1];
key.timingFunctions = @[
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]
];
[self.mask addAnimation:key forKey:@"bounds"];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
self.imageView.layer.mask = nil;
}
@end
效果基本和twitter一样,就不上图了