简体   繁体   English

动画圈成长

[英]animating a circle to grow

i am animating an UIImageView with an image of a circle that grows and fades which repeats: 我正在用重复的渐增和渐弱的圆的图像为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];
}

i call this method in viewDidAppear: 我在viewDidAppear中调用此方法:

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

    //other code
}

It will animate fine when i load mainView. 加载mainView时,动画效果会很好。 the issue is i load view2 and dismiss view2, when i come back to mainView, it is not animating anymore. 问题是我加载view2并关闭view2,当我回到mainView时,它不再设置动画了。

any ideas why this is happening? 任何想法为什么会这样?

EDIT: the methods are being called: 编辑:方法被称为:

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

EDIT 2: 编辑2:

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

dismissing view 2: 取消视图2:

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

    [self dismissModalViewControllerAnimated:YES];
}

also, i don't stop the animation myself at any point in my code. 另外,我不会在代码中的任何时候自己停止动画。

My guess is that viewDidAppear is not being called, because from the perspective of that view, it never disappears. 我的猜测是未调用viewDidAppear,因为从该视图的角度来看,它永远不会消失。

Depending on how you are creating and displaying the view2, would this work within view2 when you close it? 根据您创建和显示view2的方式,关闭view2可以在view2中使用吗?

[parentViewController viewDidAppear:YES];

i re-did some code; 我重新输入了一些代码;

-(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
}

with these changes, it behaves as i want it too. 通过这些更改,它的行为也与我想要的一样。

i think it had something to do with trying to animate the outerCircle a second time (it was already animating from first viewDidAppear, and when viewDidAppear was called a second time, it re-animated an already animating image and just borked it completely). 我认为这与尝试第二次对outerCircle进行动画处理有关(它已经从第一个viewDidAppear进行了动画处理,并且当第二次调用viewDidAppear时,它重新对了一个已经动画化的图像进行了动画处理,并使其完全枯燥了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM