美文网首页Ios@IONIC
iOS 动画之Spring动画、Block动画、GIF图

iOS 动画之Spring动画、Block动画、GIF图

作者: Joker_King | 来源:发表于2016-04-22 21:15 被阅读478次

Spring动画

Spring动画是一种特殊的动画曲线,自从iOS7之后开始被广泛应用在系统动画中。所谓的Spring动画就是动画在执行的过程中会有一个放大的效果,然后在回去。
创建Spring动画用到了下面的一个方法

- (void)springAnimation{
//Damping:阻尼值0 - 1、阻尼值越小动画越明显
//Velocity:初始速度
[UIView animateWithDuration:2.0 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:20
 options:UIViewAnimationOptionRepeat animations:^{
    self.redView.frame = CGRectMake(100, 300, 200, 200);
    self.redView.backgroundColor =[UIColor blackColor];
} completion:nil];
}

Block动画

Block简单动画

示例:在Block的回调方法内改变动画的颜色

[UIView animateWithDuration:5 animations:^{
//需要改变的属性
self.redView.backgroundColor = [UIColor cyanColor];
}];

Block复杂动画

相比较Block的简单动画来说Block的复杂动画能够在动画完成后,对动画做一些其他的操作
示例:在动画过程中改变将视图的颜色改为黄色,在动画结束的时候将视图的颜色改为红色。

[UIView animateWithDuration:2.0 animations:^{
self.redView.backgroundColor = [UIColor yellowColor];
} completion:^(BOOL finished) {
     if (finished) {//动画结束
       self.redView.backgroundColor = [UIColor redColor];
     }
}];

GIF动图

简单来说,gif图片就是将一组图片放在一起,以极快的速度切换图片,这样就能实现一个动画的效果。西面来看具体的做法。

  • 首先,我们创建一个可变数组把我们需要用到的图象存储起来。
NSMutableArray *imageArray = [NSMutableArray array];
        for (int i = 1; i < 14; i++) {
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"1-%d.tiff",i]];
            [imageArray addObject:image];
        }
  • 然后创建一个imageView来显示图片
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    imageView.center = self.view.center;
    imageView.animationImages = imageArray;
    imageView.animationDuration = 0.5;//动画执行的时间
    imageView.animationRepeatCount = 10;//动画重复次数
    [self.view addSubview:_imageView];//开启动画
    [imageView startAnimating];

在实际使用的过程中,通常我们会在不同的地方,来执行动画属性的操作,具体情况按照需求来实现。

相关文章

网友评论

    本文标题:iOS 动画之Spring动画、Block动画、GIF图

    本文链接:https://www.haomeiwen.com/subject/ftyxrttx.html