CATransform3D动画后,UIViewController无法响应触摸

3
我的“库”样式的UIViewController使用1.75弧度的CATransform3D旋转动画来隐藏它,然后将其推送(没有动画)到下一个或最后一个视图。不幸的是,当在弹出UIViewController上执行动画时,弹出的VC将不会响应触摸。
我尝试过的事情:
- 为了使动画在弹出时显示,而不是根本不进行动画,我必须延迟0.1秒才能实现。为此,我使用NSObject的performSelector:withObject:afterDelay。不幸的是,尽管完美地执行了预期的动画,但导致了我的问题。 - 使用NSTimer在0.1秒后执行操作且不重复。这什么也没做。 - 在动画时使用UIView的delay函数,这意味着不执行动画。 - 使用选择器通过被另一个引用来执行动画。没有效果。 - 在视图未响应触摸时调用touchesEnded,没有效果。
我的当前代码虽然有点杂乱(我第一次使用核心动画/ 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弧度,因此将保留该变换角度,直到旋转回来。
欢迎提供我的代码任何建议!

缩进使代码更易于阅读。更易于阅读的代码意味着更多的人会愿意帮助你。 - Jonathan.
1个回答

1

调试了 3 天后,我终于找到了答案。结果发现最好使用以下代码行来刷新整个 ViewController。它会占用更多内存,但可以修复一个巨大的 bug。

[self becomeFirstResponder];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接