[問題] NSView製作動畫

看板MacDev作者 (dryman)時間16年前 (2009/02/18 17:11), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/6 (看更多)
我想使用-(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

02/18 21:18, , 1F
應該把 scheduleTimerWith... 放在 start 裡面
02/18 21:18, 1F

02/19 15:30, , 2F
還是不行耶,因為target是self 所以按一次只動一小格
02/19 15:30, 2F

02/19 15:30, , 3F
即使把repeats弄成YES還是不行
02/19 15:30, 3F
文章代碼(AID): #19cz3OgJ (MacDev)
討論串 (同標題文章)
文章代碼(AID): #19cz3OgJ (MacDev)