首页 > 学院 > 开发设计 > 正文

UIView中的动画设置

2019-11-14 20:31:13
字体:
来源:转载
供稿:网友

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

方式一:

[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];    }}

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表