ios UIView常用动画效果

Posted 专注it

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]];

以上是关于ios UIView常用动画效果的主要内容,如果未能解决你的问题,请参考以下文章

iOS动画效果和实现

iOS动画效果三:CABAsicAnimation实现平移、旋转和放大

UIView动画效果

iOS:抽屉侧滑动画两种形式(1UIView侧滑 2ViewController侧滑)

iOS核心动画以及UIView动画的介绍

iOS学习笔记10-UIView动画