0

I need to scale a view with UIPinchGestureRecognizer but without CGAffineTransform, so how to change this code to do it without CGAffineTransform?

- (IBAction)zoomma:(UIGestureRecognizer *)sender {

    CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
    if (factor > 1) {
        self.sgungaView.transform = CGAffineTransformMakeScale(lastScaleFactor + (factor-1), lastScaleFactor + (factor-1));
    } else {
        self.sgungaView.transform = CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor * factor);
    }

    if (sender.state == UIGestureRecognizerStateEnded) { 
        if (factor > 1) {
            lastScaleFactor += (factor-1); 
        } else {
            lastScaleFactor *= factor;
        }
    }
}

Edit:

Not a masterpiece but this works

- (void)zoomma:(UIGestureRecognizer *)sender {

    CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
    if (factor > 1) {
        float enlarge = lastScaleFactor + (factor-1);
        [self.sgungaView setBounds:CGRectMake(0, 0, self.sgungaView.bounds.size.height + enlarge, self.sgungaView.bounds.size.height + enlarge)];
    } else {
        float stringi = lastScaleFactor * factor;
        [self.sgungaView setBounds:CGRectMake(0, 0, self.sgungaView.bounds.size.height - stringi, self.sgungaView.bounds.size.height - stringi)];
    }

    if (sender.state == UIGestureRecognizerStateEnded) { 
        if (factor > 1) {
            lastScaleFactor += (factor-1); 
        } else {
            lastScaleFactor *= factor;
        }
    }
}

there's a better way?

4

1 回答 1

0

您可以将 UIScrollView 添加到您的视图,并将您的元素(视图的元素)添加到 UIScrollView。然后您可以使用 UIScrollView 中的缩放委托进行缩放。

这对我很有效。

于 2011-09-01T15:21:24.433 回答