iOS-Twitter打开动画效果

#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一样,就不上图了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 178,942评论 25 709
  • 楚斯咏第一次知道什么是心动,是在很多年前的一个下午。 那个遥远却熟悉的下午,第一次见到了周屹霄。他站在军校的门口,...
    和清欢阅读 189评论 0 1
  • 降雨的空间分布从理论来讲为一个连续函数,即 式中: p - 时段或者次降雨量;x,y 地面某一点的坐标 因此区域(...
    xiaofeixiazyh阅读 17,760评论 0 1
  • DebugView是一个系统调试信息输出的捕获工具。 在程序中使用如下函数: 1> OutputDebugStri...
    星夜兼程工作笔记阅读 2,318评论 0 0
  • 心犹社会一般浮躁,很久不懂文字为何物,不懂说不懂写,流离在刷屏间失所。论坛,微博,知乎,看人说,听人言,失去自我,...
    没头脑和不高兴1982阅读 202评论 0 0

友情链接更多精彩内容