UIImageView层次结构上的手势

时间:2012-11-22 06:02:43

标签: uiimageview frame

我有一个名为“A”的基础UIImageView可以响应pinchGesture,我捏了它,在我添加子视图之前我重置了帧,它看起来很好。然后我在基础UIImageView“A”上添加了“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;
    }
}

1 个答案:

答案 0 :(得分:0)

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