【发布时间】:2012-03-21 00:34:57
【问题描述】:
我正在为 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];
}
另外,我自己不会在我的代码中的任何时候停止动画。
【问题讨论】:
-
也许
viewDidAppear没有被调用?显示视图切换代码。 -
viewDidAppear 是否被调用?自己加载 view2 时是否停止动画?
-
viewDidAppear 确实被调用并且 animateOuterCircle 确实被调用。
-
您是否使用调试器检查过您对图层的引用是否仍然有效(当动画未出现时)?向
nil发送消息时没有任何反应。
标签: objective-c ios animation