0

I have created a program and found an error that i cannot seem to work out.

I have stripped the problem out to recreate in a brand new project but it still re occurs.

The problem is when i press the BUTTON the image changes but at a much faster speed than the speed set up in NSTIMER but only the first time the button is pressed.

If i carry on pressing the button the image changes at the speed i require.

IT ONLY HAPPENS ON THE FIRST TIME ROUND AND I AM USING A TOUCH DOWN EVENT ( ALTHOUGH I HAVE TRIED TOUCH UP INSIDE )

This only happens the first time and is extremely important that the first time is the same timing as the rest.

I am aware of various discussions as to the accuracy of NSTIMER anyway , but i dont think it is relevant to my question

here is my .h

- (IBAction)slap:(id)sender {
    NSString *imagechange4 = [NSString stringWithFormat:@"onehandedplayer2.png"];
    //player2 is an UIButton IBOutlet
    [player2 setImage:[UIImage imageNamed:imagechange4]];

    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(handsback1) userInfo:nil repeats:NO];
}

-(void)handsback1 {
    NSString *imagechange3= [NSString stringWithFormat:@"hands rotated.png"];
    [player2 setImage:[UIImage imageNamed:imagechange3]];
}
4

2 回答 2

0

尝试使用 performSelector -

[self performSelector:@selector(handsback1) withObject:nil afterDelay:0.5];

这真的很容易和可靠。

于 2013-06-18T15:55:13.297 回答
0

刚刚空闲了几分钟(!)并再次遇到这个问题 - 我突然想到,当图像更改时,您可能会误认为按钮突出显示 - 您是否在 IB 的属性检查器中取消选中按钮的“突出显示调整图像”属性?

也许不太可能,但你永远不知道...

于 2013-07-08T13:16:37.757 回答