我想实现的是:
当我触摸一个按钮时,图像在 View 上显示 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;
}
关于objective-c - 在 View 上显示图像 1 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9674493/