iOS Developer

iOS动画-UIView Animation

2017-01-22  本文已影响234人  RDPCode

iOS动画-UIView Animation

众所周知动画效果在移动开发中是非常重要的,因为用户在使用app讲究两个重要的元素1,UI 2,UE。 而动画效果大大提示用户体验感,下面将我自己理解的效果。

iOS 动画函数

如图iOS能够调用的动画函数有5个


动画列表

下面我讲一一讲解

[UIView animateWithDuration: animations:]

效果展示

代码展示

    CGFloat changeY = self.view.frame.size.height * 0.7;
    
    [self.view layoutIfNeeded];
    
    [UIView animateWithDuration:1.0 animations:^{
        
        CGRect frame;
        //1.微博
        frame = _wbBtn.frame;
        frame.origin.y = changeY;
        _wbBtn.frame = frame;
        
        //2.微信
        frame = _wxBtn.frame;
        frame.origin.y = changeY;
        _wxBtn.frame = frame;
        
        //3.QQ
        frame = _qqBtn.frame;
        frame.origin.y = changeY;
        _qqBtn.frame = frame;
        
        [self.view layoutIfNeeded];
    }];

[UIView animateWithDuration: animations: completion:]

效果展示

动画2

代码展示

    CGFloat changeY = self.view.frame.size.height * 0.7;
    
    [self.view layoutIfNeeded];
    
    [UIView animateWithDuration:1.0 animations:^{
        CGRect frame;
        //1.微博
        frame = _wbBtn.frame;
        frame.origin.y = changeY;
        _wbBtn.frame = frame;
        
        //2.微信
        frame = _wxBtn.frame;
        frame.origin.y = changeY;
        _wxBtn.frame = frame;
        
        //3.QQ
        frame = _qqBtn.frame;
        frame.origin.y = changeY;
        _qqBtn.frame = frame;
        
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        //改变颜色
        [UIView animateWithDuration:1.0 animations:^{
            
            self.view.backgroundColor = [UIColor grayColor];
        }];
    }];

[UIView animateWithDuration: delay: options: animation completion:]

这里重点下 options 这个变量, 通过设置这个变量我们可以实现非常多种效果,也是精辟所在,我将抽取各别演示这个参数不同的效果。

效果展示

效果一
效果二
效果三

代码展示

    CGFloat changeY = self.view.frame.size.height * 0.7;
    
    [self.view layoutIfNeeded];
    

    [UIView animateWithDuration:2.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut   animations:^{
        CGRect frame;
        //1.微博
        frame = _wbBtn.frame;
        frame.origin.y = changeY;
        _wbBtn.frame = frame;
        
        //2.微信
        frame = _wxBtn.frame;
        frame.origin.y = changeY;
        _wxBtn.frame = frame;
        
        //3.QQ
        frame = _qqBtn.frame;
        frame.origin.y = changeY;
        _qqBtn.frame = frame;
        
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
    }];

[UIView animateWithDuration: delay: usingSpringWithDamping: initialSpringVelocity: options:animations:completion:]

效果展示

弹簧效果

代码展示

    
    CGFloat changeY = self.view.frame.size.height * 0.7;
    
    [self.view layoutIfNeeded];
    
    [UIView animateWithDuration:1.0 delay:1.0 usingSpringWithDamping:0.4 initialSpringVelocity:5 options:UIViewAnimationOptionCurveLinear animations:^{
        //1.微博
        CGRect frame;
        frame = _wbBtn.frame;
        frame.origin.y = changeY;
        _wbBtn.frame = frame;
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1.0 delay:1.0 usingSpringWithDamping:0.5 initialSpringVelocity:5 options:UIViewAnimationOptionCurveLinear animations:^{
            
            //2.微信
            CGRect frame;
            frame = _wxBtn.frame;
            frame.origin.y = changeY;
            _wxBtn.frame = frame;

        } completion:^(BOOL finished) {
            
            [UIView animateWithDuration:1.0 delay:1.0 usingSpringWithDamping:0.6 initialSpringVelocity:5 options:UIViewAnimationOptionCurveLinear animations:^{
                
                //3.QQ
                CGRect frame;
                frame = _qqBtn.frame;
                frame.origin.y = changeY;
                _qqBtn.frame = frame;
                
            } completion:^(BOOL finished) {
            }];
        }];
    }];

上一篇 下一篇

猜你喜欢

热点阅读