单击按钮时如何启动活动指示器的动画? [英] How start animation of activity indicator when click on button?

查看:29
本文介绍了单击按钮时如何启动活动指示器的动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码,其中我在滚动视图中有视图数组.在每个视图中,我创建图像视图和按钮.现在我想在按钮上设置一个事件,即当单击按钮时,活动指示器将出现在视图上并开始动画,当完成下一个视图或图像的上传时,然后停止并隐藏活动指示器.我将在代码中做什么以使其工作?那怎么办?简而言之,我想在单击按钮时在视图上显示活动指示器,并在出现整洁视图时隐藏.

I have code in which I have array of view in scroll view. In each view I create image view and button. Now i want to set a event on button that is when click on button then activity indicator will appear on view and start animation and when finish upload of next view or image then stop and hide activity indicator. What I will do in code so that it work? How do that? In short i want to display activity indicator on view when click on button and hide when neat view appear.

推荐答案

创建一个函数并在按钮单击时调用它,并将此代码添加到您的函数中

make a function and call that on button click, and add this code in your function

    spinner = [[UIActivityIndicatorView alloc]    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
    [yourView addSubview:spinner];  
    [spinner startAnimating];       
    [spinner release];  

使用它来移除微调器:[spinner removeFromSuperview];

这里是微调器,UIActivityIndi​​catorView *spinner;(我已经在 .h 的 ma 代码中声明了)

here spinner is, UIActivityIndicatorView *spinner; (I've declared in .h of ma code)

这篇关于单击按钮时如何启动活动指示器的动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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