我遇到以下代码的问题。当我执行它时,有一个未定义的延迟,首先是[CATransaction commit]
和CompletionBlock:
。不知道那里发生了什么。这只有在应用程序在设备上运行时才会发生。
这是时间日志,
2013-04-22 15:59:50.893 MyApp[27038:907] ***** A
2013-04-22 **15:59:50.894** MyApp[27038:907] ***** B
2013-04-22 **15:59:53.161** MyApp[27038:907] ***** C
2013-04-22 15:59:53.162 MyApp[27038:907] ***** D
2013-04-22 15:59:53.164 MyApp[27038:907] ***** E
2013-04-22 15:59:53.967 MyApp[27038:907] ***** F
-
NSLog(@"***** A");
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[CATransaction begin];
NSLog(@"***** D");
for (UIView *view in [masterTableView subviews])
{
if (view.tag == 501)
{
[view removeFromSuperview];
break;
}
}
[self.view sendSubviewToBack:masterTableView];
[self.view bringSubviewToFront:detailView];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setDuration:.8];
[animation setSubtype:transitionFromRight?kCATransitionFromRight:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[CATransaction setCompletionBlock:^{
NSLog(@"***** F");
for (UIView *view in [detailView subviews])
{
if (view.tag == 502)
{
[view removeFromSuperview];
break;
}
}
[self addDetailView];
[self.view sendSubviewToBack:detailView];
[self.view bringSubviewToFront:masterTableView];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setDuration:.8];
[animation setSubtype:transitionFromRight?kCATransitionFromRight:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[detailView layer] addAnimation:animation forKey:@"transition"];
}];
[[masterTableView layer] addAnimation:animation forKey:@"transition"];
NSLog(@"***** E");
}];
[CATransaction begin];
[CATransaction setCompletionBlock:^{
NSLog(@"***** C");
for (UIView *view in [self.view subviews])
{
if (view.tag == 500)
{
[view removeFromSuperview];
break;
}
}
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setDuration:0];
[animation setSubtype:transitionFromRight?kCATransitionFromRight:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[dummyView layer] addAnimation:animation forKey:@"transition"];
}];
[CATransaction commit];
[CATransaction commit];
NSLog(@"***** B");
我错了什么?请帮忙。
答案 0 :(得分:0)
当我意识到CATransaction创建了我动画的视图的快照。因此,这项任务需要一些时间,因此会出现一些延迟。
因此,作为解决方案,我现在使用视图的快照图像为UIImageView设置动画。所以现在修复了未定义的问题。