在.h文件中,我设置了Goodguy
,Building1
和2
,NSTimer
和方法falldown
。Im试图设置连接到图像的NSTimer,以便它仅在与其他图像交互时才有效
IBOutlet UIImageView *Goodguy;
IBOutlet UIImageView *Building1;
IBOutlet UIImageView *Building2;
NSTimer *GoodguyFall;
-(void)falldown;
在我成立了GoodguyFall
NSTimer
,并在图像触及另一个图像就会无效NSTimer
代码.m文件。我如何设置它,使计时器在未触及“建筑物”时有效?
-(void)viewDidLoad{
GoodguyFall = [ NSTimer scheduledTimerWithTimeInterval: 0.03 target:self selector:@selector(falldown) userInfo:nil repeats:YES];
}
-(void)falldown{
Goodguy.center = (CGPointMake(Goodguy.center.x, Goodguy.center.y + 6));
}
if (CGRectIntersectsRect(Goodguy.frame, Building1.frame)){
[GoodguyFall invalidate];
}
if (CGRectIntersectsRect(Goodguy.frame, Building2.frame)){
[GoodguyFall invalidate];
}
}
请描述您从发布的代码中收到的结果。 – Daniel
goodguy在接触到building1后不会掉下来,我如何在与每个建筑物互动后使goodguy掉落@DanielZhang –