我需要使用UIPinchGestureRecognizer缩放视图但不使用CGAffineTransform, 那么如何在没有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;
}
}
}
编辑:
不是杰作,但这有效
- (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;
}
}
}
有更好的方法吗?
答案 0 :(得分:0)
您可以将UIScrollView添加到视图中,并将您的元素(视图元素)添加到UIScrollView。然后,您可以使用UIScrollView中的zoom delegete进行缩放。
这适合我。