zoukankan      html  css  js  c++  java
  • UIView中的动画设置

    两种状态的改变通过动画来渐变,设置动画效果,一般采用的方式有以下几种:

    方式一:

    [UIView beginAnimations:(NSString *) context:<#(void *)#>];
    
    [UIView setAnimationDuration:<#(NSTimeInterval)#>];
    
    /*****这里插入需要产生动画的片段*****/    
    
    [UIViewcommitAnimations];

    其中NSString和void这两个参数可设为nil;NSTimeInterval是设置播放持续的时间,单位秒;

    方式二:

        [UIView animateWithDuration:<#(NSTimeInterval)#> animations:^{
    
            /*****这里插入需要产生动画的片段*****/
    
        }];

    NSTimeInterval依然是设置播放持续的时间,单位秒。

    方式三:

        UIView animateWithDuration:<#(NSTimeInterval)#> animations:^{
    
            /*****这里插入需要产生动画的片段*****/
    
        } completion:^(BOOL finished) {
    
            /*****这里插入播放完动画后要做的事情*****/
    
        }

    NSTimeInterval依然是设置播放持续的时间,单位秒;animations

    另外UIImageView也有播放帧动画的功能:

    - (IBAction)btnClick:(UIButton *)sender {
        //取出按钮的文本名
        NSString *title = [sender titleForState:UIControlStateNormal];
        //根据文本名在字典中取得对应的图片数量个数
        int picsCount = [_dict[title] intValue];
        
        NSMutableArray *imgArray = [NSMutableArray array] ;
        //创建图片
        //生成文件名列表
        for(int i = 0; i < picsCount; i++){
            //生成文件名 拼接全路径
            NSString *name = [NSString stringWithFormat:@"%@_%02d.jpg", title, i];
            NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
            //图片初始化及添加到数组中去
            UIImage *img = [[UIImage alloc] initWithContentsOfFile:path];
            [imgArray addObject:img];
        }
        if(!_imageView.isAnimating){        //判断是否正在播放动画,防止被打断
            _imageView.animationImages = imgArray; 
            _imageView.animationDuration = 0.1 * picsCount;  //设置动画持续时间,单位秒
            _imageView.animationRepeatCount = 1;    //设置播放次数
            [_imageView startAnimating];
        }
    }
  • 相关阅读:
    C3P0连接池详解及配置
    解决a different object with the same identifier value was already associated with the session错误
    sudo su 提示没有配置JDK environment
    MySQL 5.6 双机热备
    如何用myeclispe远程调试tomcat
    Incorrect string value: '\xF0\xA1\xA1\x92' for column 'herst' at row 1
    Mysql 慢查询设置
    Mysql的主从数据库没有同步的解决办法
    新的启程
    ASP.NET程序中常用的三十三种代码
  • 原文地址:https://www.cnblogs.com/litaowei/p/3700207.html
Copyright © 2011-2022 走看看