美文网首页
iOS开发 addSubview动画

iOS开发 addSubview动画

作者: 本本的开心牧场 | 来源:发表于2018-12-14 14:57 被阅读0次

效果


效果图

核心代码

- (void)viewDidLoad {
    [super viewDidLoad];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
        
        [myTimer fire];
        NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
        [runLoop run];
    });

}

-(void)timerAction {
    
    NSLog(@"%@",[NSThread currentThread]);
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = 0.5;
    
    NSMutableArray *values = [NSMutableArray array];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    animation.values = values;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.view addSubview:self.redView];
        [self.redView.layer addAnimation:animation forKey:nil];
    });

}

相关文章

网友评论

      本文标题:iOS开发 addSubview动画

      本文链接:https://www.haomeiwen.com/subject/gsrghqtx.html