标签:
一
//调用
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]]; |
标签:
原文地址:http://www.cnblogs.com/wanghuaijun/p/5570789.html