仅在 iphone sdk 中的捏合中增加高度?

发布于 12-04 23:39 字数 1415 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初相遇2024-12-11 23:39:11

请参阅此主题。基本上,您必须对仿射变换使用不同的值。

See this thread. Basically you have to use different values for your affine transforms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文