简体   繁体   English

在CATransform3D Animation之后,UIViewController不响应触摸

[英]UIViewController does not respond to touches after CATransform3D Animation

My "Library" style UIViewController performs a CATransform3D rotate animation with an angle of 1.75 Radians, so as to hide it before pushing (with no animation) to the next, or last view. 我的“库”样式UIViewController执行一个角度为1.75 Radians的CATransform3D旋转动画,以便在推动(没有动画)到下一个或最后一个视图之前隐藏它。 Unfortunately, when performing an animation on popping a UIViewController, the popped VC will not respond to touches. 不幸的是,在弹出UIViewController时执行动画时,弹出的VC不会响应触摸。

Things I have tried:- 我尝试过的事情: -

  • To get the animation to display after popping, rather than having it not animate at all, I have to delay it by .1 seconds. 要在弹出后显示动画,而不是让动画完全没有动画,我必须将它延迟.1秒。 To do this I use NSObject's performSelector:withObject:afterDelay. 为此,我使用NSObject的performSelector:withObject:afterDelay。 This unfortunately, while performing the animation intended perfectly, causes my name problem. 不幸的是,在完美地执行动画时,会导致我的名字问题。
  • To use NSTimer to perform the action after 0.1 seconds and without repeating. 使用NSTimer在0.1秒后执行操作而不重复。 This does nothing. 这什么都不做。
  • To use UIView's delay function while animating, and this means the animation is not performed. 在动画时使用UIView的延迟功能,这意味着不执行动画。
  • To use a selector to perform the animation by being referred to by another. 使用选择器通过被另一个引用来执行动画。 To no effect. 没有效果。
  • To call touchesEnded while the view was not responding to touches, with no effect. 在视图没有响应触摸时调用touchesEnded,没有任何效果。

My current code, while a little untidy (my first use of Core Animation/QuartzCore), is... 我当前的代码虽然有点凌乱(我第一次使用Core Animation / QuartzCore),但是......

To perform the animation if popped. 如果弹出则执行动画。

//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];

To pop the VC 弹出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];

To present the animation 呈现动画

- (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];
}

The view is rotated 1.75 radians before pushing and so will be retained at that transform angle until it is rotated back. 在推动之前视图旋转1.75弧度,因此将保持在该变换角度,直到它旋转回来。

Any tips for my code would also be appreciated! 我的代码的任何提示也将不胜感激!

I found the answer after 3 days of debugging. 经过3天的调试,我找到了答案。 Turned out I was best to use the following line to refresh the entire ViewController. 原来我最好使用以下行来刷新整个ViewController。 Memory heavy, but it fixes a huge bug. 内存很重,但它修复了一个巨大的错误。

[self becomeFirstResponder];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM