Re: [問題] NSView製作動畫

看板MacDev作者 (藍永倫)時間16年前 (2009/02/19 17:49), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/6 (看更多)
※ 引述《dryman (dryman)》之銘言: : 我想使用-(IBAction)start :(id)sender //這是一個按鈕 : 按下後,才開始繪圖 : 原本我這樣寫: : @implementation movement ^^^^^^^^ 改名成 Movement 較好,Class 應該是 CamelCase。 : -(id)initWithFrame:(NSRect)frame{ : self=[super initWithFrame:frame]; : if(self){ [self setNeedDisplay:NO]; } : return self; : } - (id) initWithFrame: (NSRect)frame { if ([super initWithFrame: frame]) { _animating = NO; } return self; } : -(IBAction)start:(id)sender{ : ... : [self setNeedDisplay:YES]; : } - (IBAction) start: (id)sender { _animating = YES; [NSTimer scheduledTimerWithTImeInterval: (1.0 / 24.0) target: self selector: @selector(handleTimer:) userInfo: nil repeats: YES]; } : -(void)handleTimer:(NSTimer*)timer{ : ... : [self setNeedDisplay:YES]; : } - (void) handleTimer: (NSTimer *)timer { if (!_animating) { [timer invalidate]; return; } [self setNeedsDisplay: YES]; } : -(void)drawRect:(NSRect)rect{ : ... : timer = [NSTimer scheduledTimerWithTimeInterval: 0.0 : target: self : selector: @selector(handleTimer:) : userInfo: nil : repeats: NO]; : } - (void) drawRect: (NSRect)rect { .... if (...) { _animating = NO; } } 沒 compile 過,你試試看吧? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.180.14

02/20 23:20, , 1F
我還沒試 謝謝教學^ ^
02/20 23:20, 1F
文章代碼(AID): #19dIj3qw (MacDev)
討論串 (同標題文章)
文章代碼(AID): #19dIj3qw (MacDev)