我在用戶界面上有一個按鈕,每按下一次按鈕,我就會每隔800毫秒閃一下(打開然後再關閉)。我這樣做,用下面的代碼:如何刷新UI線程上的按鈕?
- (void)flickEmergencyButton {
// Check whether an emergency is in progress...
if (model.emergencyInProgress) {
// ...and if so, flick the state
self.emergencyButton.selected = !self.emergencyButton.selected;
// Make this method be called again in 800ms
[self performSelector:@selector(flickEmergencyButton) withObject:nil afterDelay:0.8];
} else {
// ...otherwise, turn the button off
self.emergencyButton.selected = NO;
}
}
...它的作品真的很好,除了:有在UI上一個UIScrollView,以及和在用戶有他的手指放在上面並圍繞,滾動按鈕凍結。雖然我完全理解這是爲什麼,但我不知道該怎麼做。
performSelector:withObject:afterDelay
消息調度要在當前線程(即主線程)上發送的消息,即,用戶界面踩點,因此在所有其他用戶界面活動結束之前都無法處理該消息。正確?但我需要在UI線程上這樣做,因爲我無法選擇/取消選擇任何其他線程上的按鈕,對不對?那麼這裏的解決方案是什麼?
難道你不能只用選項* UIViewAnimationOptionRepeat *或* UIViewAnimationOptionAutoreverse * set添加動畫到按鈕嗎? –