objective-c - super View 旋转后 UIButton 未接收到触摸

标签 objective-c ios caanimation

我正在使用 UICollectionView,并且我通过子类化该类定义了自定义 UICollectionViewCell。该类的初始值设定项定义了两个 View ,如下所示:

    [[NSBundle mainBundle] loadNibNamed:@"ProtelViewCellFlipped" owner:self options:nil];

    CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
    [flippedView.layer setTransform:transform];
    [flippedView setHidden:YES];
    [self addSubview:flippedView];

    [[NSBundle mainBundle] loadNibNamed:@"ProtelViewCell" owner:self options:nil];
    [self addSubview:selfView];
    [selfView.layer setZPosition:1];

其中,flippedView 是“ProtelViewCellFlipped”xib 文件定义的 View ,selfView 是“ProtelViewCell”xib 文件中定义的 View 。 View 层次结构如下:the view hierarchy http://massimomarra.altervista.org/gerarchia.png

事情是,翻转的 View 通过 CATransform3D 旋转(就好像它是“selfView” View 的另一侧),然后隐藏。没关系,它有效。

selfView View 上有一个 UIButton。在 View 的右下角。如果我按下该按钮,则会触发此方法:

- (void)infoButtonPressed:(UIButton *)sender
{
    NSString *animationKey = (selfView.layer.zPosition > flippedView.layer.zPosition)? @"forward" : @"backwards";
    CGFloat animationDuration = 0.3;

    if (selfView.layer.zPosition > flippedView.layer.zPosition)
        [self.layer removeAllAnimations];

    CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    [rotation setValue:animationKey forKey:@"id"];
    rotation.toValue = [NSNumber numberWithFloat:M_PI];
    rotation.duration = animationDuration;
    rotation.removedOnCompletion = NO;
    rotation.fillMode = kCAFillModeForwards;
    [self.layer addAnimation:rotation forKey:animationKey];

    [self performSelector:@selector(flipLayers) withObject:nil afterDelay:animationDuration/2];
}

以便 self View 随动画旋​​转。另外,在动画期间调用此方法:

- (void)flipLayers
{
    [selfView setHidden:!selfView.hidden];
    [flippedView setHidden:!selfView.hidden];

    [selfView.layer setZPosition:flippedView.layer.zPosition];
    [flippedView.layer setZPosition:(1-selfView.layer.zPosition)];
}

这样flippedView变得可见(并且selfView隐藏),并且他的图层的zPosition变得高于selfView

现在我看到了 flippedView ,并且它显示正确。它还有一个按钮,但要触发他的操作,我必须点击另一个位置:flipped view scheme: i have to tap where the button "was" before the rotation http://massimomarra.altervista.org/s03KRJAUk7C_nP3yTXb7TBQ.png

看起来旋转只是修改了 View 的图形,但没有修改内容。 你能帮我吗?

提前感谢大家!!

最佳答案

在改变方向之前将按钮转换回身份

像这样:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{

    oneButton.transform=CGAffineTransformIdentity;
}

我不知道为什么,但它似乎有效

关于objective-c - super View 旋转后 UIButton 未接收到触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13028734/

相关文章:

objective-c - 检测 idevice 上是否安装了 facebook 应用

ios - 状态栏下的 CollectionView 标题内容

ios - MacO 和 iO 上 Safari 的 React 和 Axios GET 请求问题

ios - 使用 CAAnimation 无限旋转两个变量

objective-c - 何时使用 'self' 访问属性

iphone - 以编程方式请求访问联系人

c# - 使用 monomac/c# 实例化一个附加窗口

ios - 从 AppDelegate 和 ViewController 访问 locaitonManager

iphone - 转换一个描边的 CAShapeLayer

objective-c - 在任何时间点获取 CABasicAnimation 中扩展圆的大小