我试图制作一个NSButton(但我也可以使用iOS技术,所以欢迎任何答案)。
我有一个按钮,可以打开和关闭隐藏/启用:
-(void)textDidChange:(NSNotification *)notification
{
timerStatus = 0;
timerTest = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(changeButtonState:)
userInfo:nil
repeats:YES];
}
-(void) changeButtonState:(id) sender {
NSLog(@"%s", __FUNCTION__);
if (timerStatus == 2) return;
if (timerStatus == 0) {
timerStatus = 1;
saveButton.enabled = YES;
saveButton.hidden = NO;
} else {
timerStatus = 0;
saveButton.enabled = NO;
saveButton.hidden = YES;
}
}
该按钮闪烁正常,但在它关联的方法被触发后(在这种情况下是一个保存动作),我希望计时器停止并且按钮停止闪烁。这最后一部分令我头疼......任何帮助都表示赞赏。
- (IBAction)saveItemNotes:(id)sender
{
NSLog(@"%s", __FUNCTION__);
<do my save stuff here>
timerStatus = 2;
[timerTest invalidate];
timerTest = nil;
}
答案 0 :(得分:1)
只需在更改按钮状态的同一方法中使计时器无效。
更好的是,不要这样做。 如果要引起对界面项的注意,请使用Core Animation。