我有一个imageview。当我添加捏手势识别器时,它工作正常。但是当我们水平捏时,Imageview的宽度只能增加。当我们垂直做时,高度只能增加。我可以做到吗拜托?我编码如下,但是当我垂直向外捏时,高度只能增加。但是视图消失了。
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
UIPinchGestureRecognizer *panGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[self addGestureRecognizer:panGestureRecognizer];
[panGestureRecognizer release];
return self;
}
-(void) handlePinch:(UIPinchGestureRecognizer *)gesture
{
UIPinchGestureRecognizer *pinchGesture = (UIPinchGestureRecognizer *) gesture;
if ([pinchGesture state] == UIGestureRecognizerStateBegan){
lastTouchPosition = [pinchGesture locationInView:self];
} else if ([gesture state] == UIGestureRecognizerStateBegan || [pinchGesture state] == UIGestureRecognizerStateChanged){
CGPoint currentTouchLocation = [pinchGesture locationInView:self];
CGPoint deltaMove =[self CGPointDistance:currentTouchLocation p2:lastTouchPosition];
float distance = sqrt(deltaMove.x*deltaMove.x + deltaMove.y*deltaMove.y);
float hScale = 1 - abs(deltaMove.x)/distance * (1-pinchGesture.scale);
float vScale = 1 - abs(deltaMove.y)/distance * (1-pinchGesture.scale);
self.transform = CGAffineTransformScale([self transform], hScale, vScale);
lastTouchPosition = currentTouchLocation;
}