1

我有一个名为“A”的基本 UIImageView,它可以响应 pinchGesture,我捏了它,在我添加子视图之前我重置了框架,它看起来不错。然后我在基础UIImageView“A”上添加subView“B”,但是“B”有“A”的压缩变换,它很大(小)。我已经重置了框架。为什么会发生这种情况。如何使 B 显示原始框架。

 - (void)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer
{
    [self adjustAnchorPointForGestureRecognizer:gestureRecognizer];

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
        [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
        [gestureRecognizer setScale:1];
    }
}

- (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        UIView *piece = gestureRecognizer.view;
        CGPoint locationInView = [gestureRecognizer locationInView:piece];
        CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview];

        piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
        piece.center = locationInSuperview;
    }
}
4

1 回答 1

0

如果您将转换应用于 UIView A,则该转换将应用于其所有子视图,在您的情况下为 B。如果您不希望 B 受 A 的变换影响,可以尝试将 B 添加到 A 的超级视图中。

于 2013-06-22T23:37:37.027 回答