简体   繁体   中英

How to scale a view without CGAffineTransform

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?

You can add an UIScrollView to your view and add your elements (the elements of your view) to the UIScrollView. Then you can use the zoom delegete from UIScrollView to zoom.

This works well for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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