作者dryman (dryman)
看板MacDev
标题[问题] NSView制作动画
时间Wed Feb 18 17:11:51 2009
我想使用-(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
1F:→ yllan:应该把 scheduleTimerWith... 放在 start 里面 02/18 21:18
2F:→ dryman:还是不行耶,因为target是self 所以按一次只动一小格 02/19 15:30
3F:→ dryman:即使把repeats弄成YES还是不行 02/19 15:30