Re: [問題] NSView製作動畫
※ 引述《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
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章