zoukankan      html  css  js  c++  java
  • 各种动画集合

    经常用到各种各样的动画,所以,自己写一个简单的类别,封装一些简单的动画操作。前段时间学习了一些关联的用法。本着学以致用的原则(怕不用几天又忘了),所以在封装这个小的类别时,用关联给类别增添了几个新的属性。github地址:https://github.com/n1sunjianfei/Animation


    下面是一些简单的用法,当然,可以根据不同的起始点进行其他的动画。

    初始化一个view

    UIView *testView = [[UIView alloc]init];
        testView.frame = CGRectMake(0, 0, 280, 180);
        testView.backgroundColor = [UIColor grayColor];
        testView.layer.masksToBounds = YES;
        testView.layer.cornerRadius = 5;
        testView.animationTime = 0.5;
        
        
        __weak typeof(self) weakself=self;
        
        testView.finishedIn = ^(void){
            NSLog(@"移入");
            weakself.isShow = YES;
        };
        testView.finishedOut = ^(void){
            NSLog(@"移除");
            weakself.isShow = NO;
        };
        self.testView = testView;

    添加几个按钮用以展示动画效果:

    - (IBAction)ScaleIn:(UIButton *)sender {
        
        CGFloat width = CGRectGetWidth(self.view.frame);
        CGFloat height = CGRectGetHeight(self.view.frame);
        self.testView.center = CGPointMake(width/2, height/2);
        
        if (!_isShow) {
            [self.testView showInView_Scale:self.view];
            
        }else{
            
            [self.testView removeFromSuperView_Scale];
        }
    }
    - (IBAction)animationTest:(UIButton *)sender {
        
        CGFloat width = CGRectGetWidth(self.view.frame);
        CGFloat height = CGRectGetHeight(self.view.frame);
        
        if (!_isShow) {
            //贝赛尔曲线滑入
    //        [self.testView showInView_curve:self.view startCenter:CGPointMake(0, 0) endCenter:CGPointMake(width/2, height/2)];
            
            //直线滑入
            [self.testView showInView_curve:self.view startCenter:CGPointMake(width/2, 0) endCenter:CGPointMake(width/2, height/2)];
            
        }else{
            
    //       [self.testView removeFromSuperView_curveWithStartCenter:self.testView.center endCenter:CGPointMake(width, height)];
            [self.testView removeFromSuperView_curveWithStartCenter:self.testView.center endCenter:CGPointMake(width/2, height)];
        }
    }
    
    - (IBAction)Clickin:(UIButton *)sender {
       
        CGFloat width = CGRectGetWidth(self.view.frame);
        CGFloat height = CGRectGetHeight(self.view.frame);
        
        if (!_isShow) {
            [self.testView showInView_Moved:self.view startCenter:CGPointMake(0,0) endCenter:CGPointMake(width/2, height/2)];
            
        }else{
            
            [self.testView removeFromSuperView_MovedWithEndCenter:CGPointMake(width, height)];
        }
        
    }
    - (IBAction)CATransitionTest:(UIButton *)sender {
        
        CGFloat width = CGRectGetWidth(self.view.frame);
        CGFloat height = CGRectGetHeight(self.view.frame);
        self.testView.center = CGPointMake(width/2, height/2);
    
        if (!_isShow) {
            [self.testView showInview_Animation:self.view type:kCATransitionMoveIn subType:nil];
            
        }else{
            
            [self.testView removeFromSuperView_AnimationWithType:@"rippleEffect" subType:nil];
            
        }
    }
    - (IBAction)shake:(UIButton *)sender {
        
        CGFloat width = CGRectGetWidth(self.view.frame);
        CGFloat height = CGRectGetHeight(self.view.frame);
        self.testView.center = CGPointMake(width/2, height/2);
    
        [self.view addSubview:self.testView];
        [self.testView shake];
    }

    自己封装的类别中添加了三个属性,关键性代码为:

    //声明
    @property(nonatomic,assign) CGFloat animationTime;
    @property(nonatomic,strong) CompletionBlock finishedIn;
    @property(nonatomic,strong) CompletionBlock finishedOut;

    使用关联,写三个属性的get和set方法:

    #pragma mark - 添加animationTime,两个block属性
    
    -(void)setAnimationTime:(CGFloat)animationTime{
        return objc_setAssociatedObject(self, @selector(animationTime),[NSNumber numberWithFloat:animationTime], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
        
    }
    
    -(CGFloat)animationTime{
        
        NSNumber *timeValue = objc_getAssociatedObject(self, _cmd);
        return timeValue.floatValue==0?0.3:timeValue.floatValue;
    }
    
    -(void)setFinishedIn:(CompletionBlock)finishedIn{
        return objc_setAssociatedObject(self, @selector(finishedIn), finishedIn, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    -(CompletionBlock)finishedIn{
        return objc_getAssociatedObject(self, _cmd);
    }
    
    -(void)setFinishedOut:(CompletionBlock)finishedOut{
        return objc_setAssociatedObject(self, @selector(finishedOut), finishedOut, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    -(CompletionBlock)finishedOut{
        return objc_getAssociatedObject(self, _cmd);
    }

    Demo中只有部分动画效果,为了方便使用,在后续编码时遇到其他常用动画效果会慢慢填充进去。

  • 相关阅读:
    Django 2.1 配sql server 2008R2
    1.内网安全代理技术
    3.frp搭建socks5代理
    2.变量常量和注释
    1.域环境&工作组&局域网探针方案
    4.nps搭建socks5代理
    1.php介绍和安装
    2.内网安全隧道技术
    3.横向smb&wmi明文或hash传递
    5.域横向CobaltStrike&SPN&RDP
  • 原文地址:https://www.cnblogs.com/sunjianfei/p/7086629.html
Copyright © 2011-2022 走看看