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];
        }
    }
  • 相关阅读:
    PHP导出数据到淘宝助手CSV的方法分享
    创业日志:壹百款购物客户中心正式上线啦!
    THINKPHP+JS缩放图片式截图的实现
    入园3年来的感慨
    CentOS 5 全攻略 一步一步配置详解
    创业日记:进入电子商务领域,需未雨绸缪,更要步步谨慎
    IT商悟读书笔记
    震惊的事情一波接一波的,找自己的FREE
    创业日记:微团队,技术应用思考
    博客园我回来了!
  • 原文地址:https://www.cnblogs.com/litaowei/p/3700207.html
Copyright © 2011-2022 走看看