• ios UIView常用动画效果


    //调用

    1
    2
    3
    4
    5
    6
    if(m_viewScenario.superview == nil)<br>{
        m_viewScenario.alpha = 1.0;
        m_viewScenario.transform = CGAffineTransformIdentity;
        [self zoomIn:m_viewScenario andAnimationDuration:1.0 andWait:YES];
        [self.view addSubview:m_viewScenario];
    }

      

    //展示,由小变大

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    - (void)zoomIn: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait
    {
        __block BOOL done = wait;
        view.transform = CGAffineTransformMakeScale(0, 0);
        [UIView animateWithDuration:duration animations:^{
            view.transform = CGAffineTransformIdentity;
             
        } completion:^(BOOL finished) {
            done = NO;
        }];
        while (done == YES)
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    }

    //有大变小调用

    1
    2
    [self zoomOut:m_viewScenario andAnimationDuration:1.0 andWait:NO];
    [self removeScenarioView];

    //大变小  函数

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    - (void)zoomOut: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait{
        __block BOOL done = wait;
        view.transform = CGAffineTransformIdentity;
        [UIView animateWithDuration:duration animations:^{
            view.transform = CGAffineTransformMakeScale(0, 0);
        } completion:^(BOOL finished) {
            done = YES;
        }];
        while (done == NO)
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    }

      

    二,如果需要类似UIAlertView那种动画

    显示调用

    1
    2
    3
    4
    5
    6
    7
    8
    if(m_viewScenario.superview == nil)
    {
        m_viewScenario.alpha = 1.0;
        m_viewScenario.transform = CGAffineTransformIdentity;
        [self.view addSubview:m_viewScenario];
     
        [self zoomIn:m_viewScenario andAnimationDuration:1.0];
    }

      

    小变大动画

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    - (void)zoomIn: (UIView *)view andAnimationDuration: (float) duration
    {
        CAKeyframeAnimation * animation;
        animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
        animation.duration = duration;
        //animation.delegate = self;
        animation.removedOnCompletion = NO;
        animation.fillMode = kCAFillModeForwards;
        NSMutableArray *values = [NSMutableArray array];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
        animation.values = values;
        animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
        [view.layer addAnimation:animation forKey:nil];
    }

      

    大变小,调用同上,函数稍有变化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    - (void)zoomOut: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait{
        __block BOOL done = wait;
        view.transform = CGAffineTransformIdentity;
        [UIView animateWithDuration:duration animations:^{
            view.transform = CGAffineTransformMakeScale(0, 0);
            view.alpha = 0.0;
        } completion:^(BOOL finished) {
            done = YES;
        }];
        while (done == NO)
            [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
  • 相关阅读:
    【机器学习】作业7: 随机森林
    【机器学习】作业6-EM算法
    【分布式系统】Consistent Hashing
    北京G,计算几何,线段相交
    带权区间调度问题,软件的期中复习
    机器学习期中考复习(md全是证明题)
    hihocoder35 模板场
    缺课两周后的数值计算笔记
    跨域访问设置
    截取视频第一帧图片
  • 原文地址:https://www.cnblogs.com/wanghuaijun/p/5570789.html
Copyright © 2020-2023  润新知