[問題] NSView製作動畫
我想使用-(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
02/18 21:18, 1F
→
02/19 15:30, , 2F
02/19 15:30, 2F
→
02/19 15:30, , 3F
02/19 15:30, 3F
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章