动画一圈成长 [英] animating a circle to grow

查看:145
本文介绍了动画一圈成长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作动画的UIImageView的与生长和淡入淡出一个圆,重复的图像:

i am animating an UIImageView with an image of a circle that grows and fades which repeats:

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

i call this method in viewDidAppear:

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

    //other code
}

当我加载MAINVIEW它将动画的罚款。这个问题是我加载视图2​​和罢免视图2,当我回来MAINVIEW,它不是动画了。

It will animate fine when i load mainView. the issue is i load view2 and dismiss view2, when i come back to mainView, it is not animating anymore.

任何想法,为什么发生这种情况?

any ideas why this is happening?

编辑:方法被调用:

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];
}

另外,我也不在我的code随时停止动画自己。

also, i don't stop the animation myself at any point in my code.

推荐答案

我重新做了一些code;

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.

我认为它有事可做,试图动画outerCircle第二次(它已经从第一viewDidAppear动画,当viewDidAppear被称为第二次,它重新动画已经动画图像,只是borked它完全)。

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).

这篇关于动画一圈成长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆