我有一個UIButton,當用戶單擊按鈕時,我添加了一個UIActivtyIndicatorView。用戶點擊標記爲「GO」的UIButton,然後activityIndicator應該進入並覆蓋「GO」標題並旋轉,直到在後臺停止任何事情。將UIActivityIndicatorView添加到UIButton的頂視圖
- (void)going:(UIButton *)button {
NSLog(@"going button pressed");
goingActivity = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
goingActivity.center = button.center;
[button.superview insertSubview:goingActivity aboveSubview:button];
[goingActivity startAnimating];
if ([button.titleLabel.text isEqualToString:@"Go"]) { // Select
[PFObject saveAllInBackground:save block:^(BOOL success, NSError *error) {
//Do stuff
if (success) {
[self selectGoingButton:button]; // Toggle Button
selectedGoingToButton = button;
[defaults synchronize];
[self reloadData]; // Refresh tableview
}
}];
}
else { // Deselect
if (success) {
//Toggle button
selectedGoingToButton = nil;
[self deselectGoingButton:button];
[self reloadData];
}
}];
}
}
- (void)selectGoingButton:(UIButton *)button {
NSLog(@"GoingButtonselected");
[button setTitle:@"Going" forState:UIControlStateNormal];
button.layer.borderColor = neonBlue.CGColor;
[button setNeedsDisplay];
}
這是處理問題的代碼。我刪除了代碼的肉,但所做的是更新解析上的用戶信息,並在磁盤上,因此它不相關。問題仍然是,當activityIndicator正在運行時,按鈕標題不會消失(標題和微調器都可以看到),然後標題切換到「GOING」,然後微調器停止。
我想要這樣,當用戶點擊按鈕時,activityIndicator啓動,覆蓋按鈕標題,然後在後臺活動停止時按鈕標題切換到「GOING」。我如何讓activityIndicatorView覆蓋標題圖層?
編輯:澄清,activityIndicator被正確定位。它在按鈕的中間,可以在那裏看到很好。問題在於它沒有覆蓋標題爲「GO」的按鈕的頂層。當我添加activityIndicator子視圖時,我希望標題消失,但這不會發生在我當前的代碼中。
當活動指示器旋轉時,你不需要按鈕標題嗎? –
正確@KathiravanG – mufc