使用UIAlertVIew添加子视图,如动画,具有弹跳效果 [英] Add subview with UIAlertVIew like animation,with a bouncing effect

查看:107
本文介绍了使用UIAlertVIew添加子视图,如动画,具有弹跳效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS中添加子视图时提供反弹或弹出式动画?
我需要类似于 UIAlertView 外观风格的东西。我知道有几种方法可以做同样的事情:但我更喜欢在这里使用基本的 [UIView animateWithDuration:...]; 块,所以我可以得到一些关于 transform 我应该在这里使用弹出效果吗?



谢谢


<用于PopUp风格的div class =h2_lin>解决方案

动画



Swift



  yourView.transform = CGAffineTransformMakeScale(0.01,0.01)
UIView.animateWithDuration(0.2,延迟:0,选项: .CurveEaseOut,动画:{() - > Void in
yourView.transform = CGAffineTransformIdentity
},完成:{(已完成:Bool) - > Void in
//做一次事动画结束,把它放在这里
})

反向动画 隐藏 相同的视图

  yourView.transform = CGAffineTransformIdentity 
UIView.animateWithDuration(0.2,延迟:0,o ptions:.CurveEaseOut,动画:{() - >无效
yourView.transform = CGAffineTransformMakeScale(0.01,0.01)
},完成:{(已完成:Bool) - >无效
//动画完成后做一些事情,把它放在这里
yourView.hidden = true
})



Objective-C



  yourView.transform = CGAffineTransformMakeScale(0.01,0.01); 
[UIView animateWithDuration:0.2 delay:0选项:UIViewAnimationOptionCurveEaseOut动画:^ {
yourView.transform = CGAffineTransformIdentity;
}完成:^(BOOL完成){
//动画完成后做一些事情,把它放在这里
}];

反向动画隐藏 相同的视图

  yourView .transform = CGAffineTransformIdentity; 
[UIView animateWithDuration:0.2 delay:0选项:UIViewAnimationOptionCurveEaseOut动画:^ {
yourView.transform = CGAffineTransformMakeScale(0.01,0.01);
}完成:^(BOOL完成){
yourView.hidden = YES;
}];


How to give a bounce or pop up style animation while adding a subview in iOS? I need something similar to UIAlertView appearance style. I know there are several methods to do the same: but I prefer to use basic [UIView animateWithDuration: ...]; block here, so may I get some help regarding the transform I should use here to get the pop up effect?

Thanks

解决方案

Animation for PopUp style :

Swift

yourView.transform = CGAffineTransformMakeScale(0.01, 0.01)
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in
    yourView.transform = CGAffineTransformIdentity
}, completion: {(finished: Bool) -> Void in       
    // do something once the animation finishes, put it here
})

Reverse Animation with hiding the same View

yourView.transform = CGAffineTransformIdentity
UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in     
   yourView.transform = CGAffineTransformMakeScale(0.01, 0.01)  
}, completion: {(finished: Bool) -> Void in
   // do something once the animation finishes, put it here
   yourView.hidden = true
})

Objective-C

yourView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    yourView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
    // do something once the animation finishes, put it here
}];

Reverse Animation with hiding the same View

 yourView.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    yourView.transform = CGAffineTransformMakeScale(0.01, 0.01);
} completion:^(BOOL finished){
    yourView.hidden = YES;
}];

这篇关于使用UIAlertVIew添加子视图,如动画,具有弹跳效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆