objective-c - 在 View 上显示图像 1 秒

标签 objective-c ios uiimageview nstimer

我想实现的是:

当我触摸一个按钮时,图像在 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/

相关文章:

ios - UIButtonBarItem 中的 UISegmentedControl

ios - 在哪里以及如何__bridge

iOS地理围栏;这会比我现在拥有的更准确吗?

iOS swift Aspect Fit 左放置

ios - 如果 UIImage 设置为 .scaleAspectFill,它会与标签重叠

ios - 如何再次提示 CKApplicationPermissionUserDiscoverability

ios - 我们是否需要为每次绘制创建一个新的 RenderPassDescriptor,或者我们可以缓存它并重用它?

ios - 如何删除隐藏的 UIImage 空间?

iphone - 位置服务权限未保存 iOS

iPhone iOS 如何通过长按将图像粘贴到 UIImageView 中