美文网首页
iOS开发中的小技巧2:UIView缓冲出现

iOS开发中的小技巧2:UIView缓冲出现

作者: 莫离_焱 | 来源:发表于2017-03-18 13:39 被阅读15次

开发中有时需要动态加载一些图像,突然出现会有突兀感,所以需要有一个缓冲;此时可以用UIView aanimateWithDuration的方法实现动画效果。

@interface UIView(UIViewAnimationWithBlocks)

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL

其中 :duration为动画时间  animations为动画

下面是可以设置动画效果的属性:

frame、bounds、center、transform、alpha、backgroundColor、contentStretch

例如frame:(两秒出现完全)

[UIView animateWithDuration:0.20 animations:^{

button.frame = CGRectMake(51, 50, 80, 2);

}];

例如淡出、出现

[UIView animateWithDuration:1.0 animations:^{

firstView.alpha = 0.0;

secondView.alpha = 1.0;

}];


completion为动画执行完毕以后执行的代码块

options为动画执行的选项。

delay为动画开始执行前等待的时间

相关文章

网友评论

      本文标题:iOS开发中的小技巧2:UIView缓冲出现

      本文链接:https://www.haomeiwen.com/subject/whzzwttx.html