淡出后如何隐藏物品(Objective-C)

时间:2014-03-03 04:06:47

标签: ios objective-c animation

我有以下if语句,

if (CGRectIntersectsRect(car.frame, car2.frame) && (upMovement = -1 ) && (car2.hidden == NO)){
    [self bounce];
    [self carexplode];
    if (car2used == NO) {
        addedScore = 1;
        car2Used = YES;
    }
    car2.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"car2flames.png"], nil];
    [car2 setAnimationRepeatCount:0];
    car2.animationDuration = 20;
    [car2 startAnimating];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:4];
    [iceblock6 setAlpha:0];
    [UIView commitAnimations];
    car2.hidden = YES;

基本上,我希望它执行方法的顶部,如果一辆车撞到它,然后使用UIView动画^^,我希望它淡出,然后隐藏,这样我就可以将隐藏设置为否当它重新进入视图时(在它退出屏幕后重新加载到屏幕顶部)。但有了这个,它就会自动隐藏,没有4秒的淡出动画。我怎样才能解决这个问题?我已经尝试将car2.hidden放在if语句中,但我不知道该放入什么条件,因为UIView不是真正的bool或整数等等。有人有什么建议吗?

1 个答案:

答案 0 :(得分:0)

    [UIView animateWithDuration:1.0 delay:0.0 options:(UIViewAnimationOptions) animations:^{
        //place your animation here
        [iceblock6 setAlpha:0];
    } completion:^(BOOL finished) {
        //called when animation did finish. do what you want
        car2.hidden = YES;
    }];

其他方式:

{
...
if (CGRectIntersectsRect(car.frame, car2.frame) && (upMovement = -1 ) && (car2.hidden == NO)){
    [self bounce];
    [self carexplode];
    if (car2used == NO) {
        addedScore = 1;
        car2Used = YES;
    }
    car2.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"car2flames.png"], nil];
    [car2 setAnimationRepeatCount:0];
    car2.animationDuration = 20;
    [car2 startAnimating];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:4.0];
    [iceblock6 setAlpha:0];
    [UIView commitAnimations];

    [self performSelector:@selector(hideCar2) withObject:self afterDelay:4.0];
}

-(void)hideCar2
{
    car2.hidden = YES;
}