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

开发中有时需要动态加载一些图像,突然出现会有突兀感,所以需要有一个缓冲;此时可以用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为动画开始执行前等待的时间

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容