仅在 iphone sdk 中的捏合中增加高度?
我有一个 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;
}
I have one imageview.when i add pinch gesture recognizer,it works fine.but when we do pinchout horizontally, width of Imageview only must be increased.when we do vertically,height only must be increased.how can i do it please?I have coded as following,but when i pinch out vertically,height only must increased.but the view is disappeared.
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

请参阅此主题。基本上,您必须对仿射变换使用不同的值。
See this thread. Basically you have to use different values for your affine transforms.