开发者

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 {

    开发者_如何学JAVACGFloat 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜