博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios UIView常用动画效果
阅读量:6674 次
发布时间:2019-06-25

本文共 3020 字,大约阅读时间需要 10 分钟。

//调用

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://wbgxo.baihongyu.com/

你可能感兴趣的文章
.NET I/O 学习笔记:目录和文件
查看>>
pgpool-II3.1 的begin transaction 和 自动追加 BEGIN/COMMIT问题
查看>>
(转)记hadoop故障一例:BlockAlreadyExistsException
查看>>
hdu 4284 Travel floyd + 状压DP
查看>>
相似数据检测算法
查看>>
spring中的设计模式Observer pattern
查看>>
Lazarus 1.0.2 发布,Pascal 集成开发环境
查看>>
centos 7 中的 systemd
查看>>
Apple Watch已向微信开放WatchKit接口?
查看>>
数学图形(1.46)高次方程曲线
查看>>
Unitity 常用工具类
查看>>
广东省-IT公司红黑榜排名
查看>>
键盘过滤驱动
查看>>
SSL工作原理
查看>>
iOS中block实现的探究
查看>>
Hadoop JobHistory
查看>>
GridView编辑删除操作
查看>>
KMP算法的实现(Java语言描述)
查看>>
session销毁
查看>>
菜鸟学Java(二十二)——重新认识泛型
查看>>