看板 MacDev 關於我們 聯絡資訊
我想使用-(IBAction)start :(id)sender //這是一個按鈕 按下後,才開始繪圖 原本我這樣寫: @implementation movement -(id)initWithFrame:(NSRect)frame{ self=[super initWithFrame:frame]; if(self){ [self setNeedDisplay:NO]; } return self; } -(IBAction)start:(id)sender{ ... [self setNeedDisplay:YES]; } -(void)handleTimer:(NSTimer*)timer{ ... [self setNeedDisplay:YES]; } -(void)drawRect:(NSRect)rect{ ... timer = [NSTimer scheduledTimerWithTimeInterval: 0.0 target: self selector: @selector(handleTimer:) userInfo: nil repeats: NO]; } 可是他不管我,照樣在開始的時候自己跑動畫 後來我多弄一個bool的變數,在init的時候設為0 action會將其設成1; drawRect裡面就判定bool是不是1 但還是失敗 這樣他完全不會動... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.234
yllan:應該把 scheduleTimerWith... 放在 start 裡面 02/18 21:18
dryman:還是不行耶,因為target是self 所以按一次只動一小格 02/19 15:30
dryman:即使把repeats弄成YES還是不行 02/19 15:30