zoukankan      html  css  js  c++  java
  • UILabel的缩放动画效果

    UILabel的缩放动画效果

    效果图

    源码

    https://github.com/YouXianMing/Animations

    //
    //  ScaleLabel.h
    //  Animations
    //
    //  Created by YouXianMing on 15/12/17.
    //  Copyright © 2015年 YouXianMing. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface ScaleLabel : UIView
    
    /**
     *  Label's text.
     */
    @property (nonatomic, strong) NSString *text;
    
    /**
     *  Label's color.
     */
    @property (nonatomic, strong) UIFont   *font;
    
    /**
     *  The Label's scale before the animation start.
     */
    @property (nonatomic, assign) CGFloat   startScale;
    
    /**
     *  The label's scale after the animation ended.
     */
    @property (nonatomic, assign) CGFloat   endScale;
    
    /**
     *  The show label's color.
     */
    @property (nonatomic, strong) UIColor  *backedLabelColor;
    
    /**
     *  The animated label's color.
     */
    @property (nonatomic, strong) UIColor  *colorLabelColor;
    
    /**
     *  Start animation.
     */
    - (void)startAnimation;
    
    @end
    //
    //  ScaleLabel.m
    //  Animations
    //
    //  Created by YouXianMing on 15/12/17.
    //  Copyright © 2015年 YouXianMing. All rights reserved.
    //
    
    #import "ScaleLabel.h"
    
    @interface ScaleLabel ()
    
    @property (nonatomic, strong) UILabel  *backedLabel;
    @property (nonatomic, strong) UILabel  *colorLabel;
    
    @end
    
    @implementation ScaleLabel
    
    - (instancetype)initWithFrame:(CGRect)frame {
        
        if (self = [super initWithFrame:frame]) {
            
            _backedLabel = [[UILabel alloc] initWithFrame:self.bounds];
            _colorLabel  = [[UILabel alloc] initWithFrame:self.bounds];
            
            _backedLabel.alpha = 0;
            _colorLabel.alpha  = 0;
            
            _backedLabel.textAlignment = NSTextAlignmentCenter;
            _colorLabel.textAlignment  = NSTextAlignmentCenter;
            
            [self addSubview:_backedLabel];
            [self addSubview:_colorLabel];
        }
        
        return self;
    }
    
    - (void)startAnimation {
        
        if (_endScale == 0) {
            
            _endScale = 2.f;
        }
        
        [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:7 initialSpringVelocity:4 options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             
                             _backedLabel.alpha     = 1.f;
                             _backedLabel.transform = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
                             
                             _colorLabel.alpha      = 1.f;
                             _colorLabel.transform  = CGAffineTransformMake(1, 0, 0, 1, 0, 0);;
                             
                         } completion:^(BOOL finished) {
                             
                             [UIView animateWithDuration:2 delay:0.5 usingSpringWithDamping:7 initialSpringVelocity:4
                                                 options:UIViewAnimationOptionCurveEaseInOut
                                              animations:^{
                                                  
                                                  _colorLabel.alpha     = 0.f;
                                                  _colorLabel.transform = CGAffineTransformMake(_endScale, 0, 0, _endScale, 0, 0);
                                                  
                                              } completion:nil];
                         }];
    }
    
    
    #pragma mark - Overwrite getter & setter methods.
    @synthesize text = _text;
    - (void)setText:(NSString *)text {
        
        _text             = text;
        _backedLabel.text = text;
        _colorLabel.text  = text;
    }
    
    - (NSString *)text {
        
        return _text;
    }
    
    @synthesize startScale = _startScale;
    - (void)setStartScale:(CGFloat)startScale {
        
        _startScale            = startScale;
        _backedLabel.transform = CGAffineTransformMake(startScale, 0, 0, startScale, 0, 0);
        _colorLabel.transform  = CGAffineTransformMake(startScale, 0, 0, startScale, 0, 0);
    }
    
    - (CGFloat)startScale {
        
        return _startScale;
    }
    
    @synthesize font = _font;
    - (void)setFont:(UIFont *)font {
        
        _font             = font;
        _backedLabel.font = font;
        _colorLabel.font  = font;
    }
    
    - (UIFont *)font {
        
        return _font;
    }
    
    @synthesize backedLabelColor = _backedLabelColor;
    - (void)setBackedLabelColor:(UIColor *)backedLabelColor {
        
        _backedLabelColor      = backedLabelColor;
        _backedLabel.textColor = backedLabelColor;
    }
    
    @synthesize colorLabelColor = _colorLabelColor;
    - (void)setColorLabelColor:(UIColor *)colorLabelColor {
        
        _colorLabelColor      = colorLabelColor;
        _colorLabel.textColor = colorLabelColor;
    }
    
    @end

    细节

  • 相关阅读:
    开源一些C#不常用知识(附上DEMO)
    开源:C# 代码自动生成工具,支持站点前后台
    Xposed 集成 Android 6.0.1环境中,总结
    Android 视频通信,低延时解决方案
    Android studio,第一个生成,调用成功的jni(说多了都是泪)
    C#之文件缓存
    JavaScript 基本常识
    排序算法
    LeetCode:字符串转换整数 (atoi)
    LeetCode:判断回文数
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5053065.html
Copyright © 2011-2022 走看看