美文网首页
iOS 简单实现label点击放大动画

iOS 简单实现label点击放大动画

作者: 翻滚的炒勺2013 | 来源:发表于2017-07-16 07:32 被阅读95次

    先看效果

    Untitled.gif

    代码很简单懒加载一个label.然后把他添加到self.view

    
    - (UILabel *)label {
        if (_label == nil) {
            _label = [[UILabel alloc]initWithFrame:CGRectMake(100, 50, 120, 21)];
            _label.text = @"我会放大";
            _label.textColor = [UIColor redColor];
            _label.userInteractionEnabled = YES;
            _label.layer.shadowOpacity = 1;
            _label.layer.shadowColor = [UIColor blueColor].CGColor;
            _label.layer.shadowOffset = CGSizeMake(1, 1);
            UITapGestureRecognizer *tapRecognizerBottom =
            [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondToTapGesture:)];
           
            [_label addGestureRecognizer:tapRecognizerBottom];
            
        }
        
        return _label;
    }
    
    
        [self.view addSubview:self.label];
    
    

    在点击事件中添加帧动画

    - (void)respondToTapGesture:(UITapGestureRecognizer *)ges {
        UIView *targetView = ges.view;
        
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
        animation.keyPath = @"transform.scale";
        animation.values = @[@0.2,@20.8,@0.9,@1.0];
        animation.duration = 0.3;
        animation.calculationMode = kCAAnimationPaced;
        //把动画添加上去就OK了
        [targetView.layer addAnimation:animation forKey:nil];
    }
    

    总结添加动画很简单,会给label加,其他的view层也是一样的,所以tabbar点击动画原理也是这样的

    相关文章

      网友评论

          本文标题:iOS 简单实现label点击放大动画

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