如何在iOS中隐藏和取消隐藏图像?

时间:2015-05-22 20:19:26

标签: ios objective-c

- (IBAction)press:(id)sender {
    UIImage *bomb = [UIImage imageNamed:@"bom"];
    UIImageView *bom =[[UIImageView alloc] initWithImage:bomb];
    [bom setFrame: CGRectMake(83,115,35,35)];
    [self.view addSubview:bom];

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
        [bom setFrame:CGRectMake(149,47,35,35)];



    }
                     completion:^(BOOL finished)
     {
         [bom setFrame:CGRectMake(134,40,60,55)];
         [bom setImage:[UIImage imageNamed:@"splash"]];



         hits++;
         _hit.text=[NSString stringWithFormat:@"%i",hits];
     }];

}

这是我的代码!这里的对象bom处理splash.png图像的imageview,我希望每次按下按钮时该图像只出现0.5秒

1 个答案:

答案 0 :(得分:0)

您可以设置一个NSTimer来调用隐藏图像的方法。你必须保留对炸弹的引用。

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

-(void)hideImage {
    self.bomb.hidden = YES;
}