单击按钮时如何启动活动指示器的动画?

问题描述:

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

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)