3

我的“图书馆”风格的 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 弧度,因此将保持在该变换角度,直到它被旋转回来。

我的代码的任何提示也将不胜感激!

4

1 回答 1

1

经过3天的调试,我找到了答案。原来我最好使用以下行来刷新整个 ViewController。内存很重,但它修复了一个巨大的错误。

[self becomeFirstResponder];
于 2012-12-19T21:31:20.977 回答