【问题标题】:How start animation of activity indicator when click on button?单击按钮时如何启动活动指示器的动画?
【发布时间】:2011-10-14 01:24:31
【问题描述】:
我的代码中有滚动视图中的视图数组。在每个视图中,我创建图像视图和按钮。现在我想在按钮上设置一个事件,当单击按钮时,活动指示器将出现在视图上并开始动画,当完成下一个视图或图像的上传时,然后停止并隐藏活动指示器。我将在代码中做什么以使其工作?怎么做?简而言之,我想在单击按钮时在视图上显示活动指示器,并在出现整洁视图时隐藏。
【问题讨论】:
标签:
iphone
xcode
uiview
uiscrollview
uibutton
【解决方案1】:
创建一个函数并在单击按钮时调用它,并将此代码添加到您的函数中
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];
这里是微调器,UIActivityIndicatorView *spinner;(我已经在 ma 代码的 .h 中声明)