我对以下代码有疑问。当我执行它时,首先有一个未定义的延迟[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");
我是不是搞错了什么??请帮忙。