我要实现的是:

当我触摸按钮时,图像在视图上显示1秒钟,然后图像消失。

我知道NSTimer会有所帮助,但是我不知道如何编写正确的代码...需要您的帮助,谢谢。

- (IBAction)bodytouched:(id)sender {
bodytouchedimage.hidden = NO;
    bodytouchedimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beated.jpg"]];
    bodytouchedimage.userInteractionEnabled = YES;
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showPictures:) userInfo:nil repeats:NO];
}


- (void)showPictures:(NSTimer *)timer {
bodytouchedimage.hidden = YES;
}

最佳答案

当您触摸按钮时,应该调用showPictures函数,然后在showPictures方法中添加一个NSTimer,它将在1秒后调用hidePictures方法。

- (void)showPictures
{
    bodytouchedimage.hidden = NO;
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(hidePictures) userInfo:nil repeats:NO];
}

- (void)hidePictures
{
    bodytouchedimage.hidden = YES;
}

10-06 02:55