码迷,mamicode.com
首页 > 移动开发 > 详细

ios UIView常用动画效果

时间:2016-06-08 18:40:53      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

//调用

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常用动画效果

标签:

原文地址:http://www.cnblogs.com/wanghuaijun/p/5570789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!