动画圆圈成长

时间:2012-03-15 17:14:53

标签: objective-c ios animation

我正在为UIImageView制作动画,其中包含一个生长和渐弱的圆圈图像:

-(void)animateOuterCircle
{
    NSLog(@"animating circles");
    [UIView animateWithDuration:1.5 
                          delay:.5
                        options:(UIViewAnimationOptionAllowUserInteraction)
                     animations:^{
                         self.outerCircle.transform=CGAffineTransformMakeScale(.25, .25);
                     }
                     completion:nil];


    [UIView animateWithDuration:1.5 
                          delay:.5
                        options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction)
                     animations:^{    
                         self.outerCircle.transform=CGAffineTransformMakeScale(1.5, 1.5);
                         self.outerCircle.alpha = 0;
                     }
                     completion:nil];

    [self.view bringSubviewToFront:self.outerCircle];
}

我在viewDidAppear中调用此方法:

- (void)viewDidAppear:(BOOL)animated
{        
    [self performSelectorOnMainThread:@selector(animateOuterCircle) withObject:nil waitUntilDone:NO];

    //other code
}

当我加载mainView时它会动画很好。问题是我加载view2并关闭view2,当我回到mainView时,它不再是动画了。

为什么会发生这种情况?

编辑:正在调用这些方法:

2012-03-15 14:11:13.946[1529:17903] view2 canceled  //dismissing view2
2012-03-15 14:11:13.947[1529:17903] mapView viewWillAppear fired
2012-03-15 14:11:13.948[1529:17903] mapView viewWillAppear end
2012-03-15 14:11:14.352[1529:17903] mapView viewDidAppear fired
2012-03-15 14:11:14.353[1529:17903] animating circles
2012-03-15 14:11:14.354[1529:17903] mapView viewDidAppear end

编辑2:

-(IBAction) fourthBtn:(id)sender
{
    view2 *view2 = [self.storyboard instantiateViewControllerWithIdentifier:@"view2"];
    [self presentModalViewController:view2 animated:YES];    
}

驳回观点2:

-(IBAction) cancel:(id) sender
{    
    NSLog(@"heir canceled");

    [self dismissModalViewControllerAnimated:YES];
}

另外,我不会在我的代码中随时停止动画。

2 个答案:

答案 0 :(得分:0)

我的猜测是没有调用viewDidAppear,因为从该视图的角度来看,它永远不会消失。

根据您创建和显示view2的方式,当您关闭它时,它会在view2中工作吗?

[parentViewController viewDidAppear:YES];

答案 1 :(得分:0)

我重新做了一些代码;

-(void)viewWillDisappear:(BOOL)animated
{
    [self.outerCircle removeFromSuperview];
    [self.innerCircle removeFromSuperview];
}

- (void)viewDidAppear:(BOOL)animated
{
    self.innerCircle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"inner-circle.png"]];
    self.innerCircle.frame = CGRectMake(self.innerCircle.frame.origin.x, self.innerCircle.frame.origin.y, 30, 30);

    self.outerCircle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"outer-circle.png"]];
    self.outerCircle.frame = CGRectMake(self.outerCircle.frame.origin.x, self.outerCircle.frame.origin.y, 40, 40);

    [self.view insertSubview:self.innerCircle belowSubview:HUD];
    [self.view insertSubview:self.outerCircle belowSubview:HUD];

//other code
}

通过这些更改,它的行为也是我想要的。

我认为这与尝试第二次为outerCircle设置动画有关(它已经从第一次viewDidAppear动画了,当第二次调用viewDidAppear时,它重新动画了已经制作动画的图像并完全将它完全塞了)。