我有一个集合视图。我尝试使用故事板但无法添加。现在如何创建一个延迟2.0秒的uiactivity指示器。这应该以编程方式位于我的集合视图的中间位置
任何可以帮助我。我是ios的新手。我试过但没动画看。请帮帮我。
我试过这段代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//self.navigationItem.hidesBackButton = YES;
programaticActivityIndicatorView_ = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[self.programaticActivityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.programaticActivityIndicatorView setHidesWhenStopped:YES];
[self.programaticActivityIndicatorView setCenter:CGPointMake(150, 239)];
[self performSelector:@selector(methodsq) withObject:nil afterDelay:3.0];
[self.view addSubview:self.programaticActivityIndicatorView];
}
-(void)methodsq {
[programaticActivityIndicatorView_ startAnimating];
}
但我不断动画,但我需要动画只有3.0秒,之后它应该隐藏 谢谢!
答案 0 :(得分:0)
声明属性
@property (strong, nonatomic) UIActivityIndicatorView *indicator;
合成它
@synthesize indicator;
创建流程
CGRect rect = [[UIScreen mainScreen] bounds];
self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
self.indicator.frame = CGRectMake((rect.size.width-50)/2, (rect.size.height-50)/2, 50, 50);
self.indicator.hidesWhenStopped = YES;
[self.view addSubview:self.indicator];
开始流程
[self.indicator performSelector:@selector(startAnimating) withObject:nil afterDelay:0.1];
隐藏您想要的内容
[self.indicator performSelector:@selector(stopAnimating) withObject:nil afterDelay:2.0];