【发布时间】:2012-12-18 17:05:15
【问题描述】:
我的“库”样式 UIViewController 执行 CATransform3D 旋转动画,角度为 1.75 弧度,以便在将其推送(没有动画)到下一个或最后一个视图之前隐藏它。不幸的是,在弹出 UIViewController 时执行动画时,弹出的 VC 不会响应触摸。
我尝试过的事情:-
- 要让动画在弹出后显示,而不是让它完全没有动画,我必须将它延迟 0.1 秒。为此,我使用 NSObject 的 performSelector:withObject:afterDelay。不幸的是,虽然完美地执行了预期的动画,却导致了我的名字问题。
- 使用 NSTimer 在 0.1 秒后执行该操作且不重复。这无济于事。
- 动画时使用 UIView 的延迟功能,即不执行动画。
- 使用选择器通过被另一个选择器引用来执行动画。没有效果。
- 在视图未响应触摸时调用 touchesEnded,但没有任何效果。
我当前的代码虽然有点不整洁(我第一次使用 Core Animation/QuartzCore),但...
在弹出时执行动画。
//To collect it in the SecondVC
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(coolAnimation) name:@"ReturnSecond" object:nil];
//To send it from the ThirdVC
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReturnSecond" object:nil];
弹出 VC
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReturnWeird" object:nil];
NSUInteger integer = [[self.navigationController viewControllers] indexOfObject:self];
[[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:integer-1] animated:NO];
展示动画
- (void)coolAnimation
{
[self performSelector:@selector(tryThis) withObject:nil afterDelay:0.1];
}
- (void)tryThis
{
CGRect framer = self.view.layer.frame;
self.view.layer.anchorPoint = CGPointMake(0.f, 0.f);
self.view.layer.frame = framer;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
CATransform3D rotationAndPerspectiveTransforms = CATransform3DIdentity;
rotationAndPerspectiveTransforms.m34 = 1.0 / 500;
rotationAndPerspectiveTransforms = CATransform3DRotate(rotationAndPerspectiveTransforms, 0, 0, 1, 0);
self.view.layer.transform = rotationAndPerspectiveTransforms;
[UIView commitAnimations];
CGRect framers = flippedCell.layer.frame;
flippedCell.layer.anchorPoint = CGPointMake(0.f, 0.f);
flippedCell.layer.frame = framers;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7];
CATransform3D rotateTransform = CATransform3DIdentity;
rotateTransform.m34 = 1.0 / 500;
rotateTransform = CATransform3DRotate(rotateTransform, 0, 0, 1, 0);
flippedCell.layer.transform = rotateTransform;
[UIView commitAnimations];
[self performSelector:@selector(cellAnimationDidStop) withObject:nil afterDelay:0.7];
}
- (void)cellAnimationDidStop
{
[self.tableView reloadData];
}
视图在推动前旋转了 1.75 弧度,因此将保持在该变换角度,直到它被旋转回来。
我的代码的任何提示也将不胜感激!
【问题讨论】:
-
缩进让代码更容易阅读。更容易阅读代码意味着会有更多人愿意帮助您。
标签: ios quartz-core