3
出于某种原因,如果动画添加到子视图的层添加子视图之后直接CATransition将无法运行动画:如果CATransition在子视图添加后直接添加到子视图图层,为什么它不能工作?
transitionView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[transitionView setBackgroundColor:[UIColor redColor]];
[[self contentView] addSubview:transitionView];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:@"cube"];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setSubtype:@"fromRight"];
[self performSelector:@selector(animate) withObject:nil afterDelay:0.00001];
:
transitionView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[transitionView setBackgroundColor:[UIColor redColor]];
[[self contentView] addSubview:transitionView];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:@"cube"];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setSubtype:@"fromRight"];
[[transitionView layer] addAnimation:animation forKey:nil];
但是如果动画稍有延迟后添加
-
- (void)animate
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:@"cube"];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setSubtype:@"fromRight"];
[[transitionView layer] addAnimation:animation forKey:nil];
}
如预期的转变将工作。这有什么理由吗?
此外,您可能要设置背景颜色为'clearColor'刷新之前,再经过其更改为'redColor'冲洗。 – 2012-03-04 05:09:37