屏幕坐标与CGAffineTransform

时间:2012-03-28 13:41:12

标签: iphone objective-c

我使用手势触控功能旋转调整图像大小。现在我想做的是当图像碰到某个X时,Y点从视图中消失。

当我使用CGpoint时,它运行良好。

如何从CGTransform Matrix

中获取(x y)坐标

我目前使用的代码是

- (void)updateOriginalTransformForTouches:(NSSet *)touches 
{
    if ([touches count] > 0) {
        CGAffineTransform incrementalTransform = [self incrementalTransformWithTouches:touches];
        [self setConstrainedTransform:CGAffineTransformConcat(originalTransform, incrementalTransform)];
        originalTransform = self.transform;
    }
}

// At start, store the touch begin points and set an original transform
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    [[self superview] bringSubviewToFront:self];
    NSMutableSet *currentTouches = [[[event touchesForView:self] mutableCopy] autorelease];
    [currentTouches minusSet:touches];
    if ([currentTouches count] > 0) {
        [self updateOriginalTransformForTouches:currentTouches];
        [self cacheBeginPointForTouches:currentTouches];
    }
    [self cacheBeginPointForTouches:touches];
}

// During movement, update the transform to match the touches
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    CGAffineTransform incrementalTransform = [self incrementalTransformWithTouches:[event touchesForView:self]];
    [self setConstrainedTransform:CGAffineTransformConcat(originalTransform, incrementalTransform)];

    NSLog(@"%f",incrementalTransform.tx);
    NSLog(@"%f",incrementalTransform.ty);

    if (incrementalTransform.tx == 44 && incrementalTransform.ty == 281) {
        NSLog(@"dvvd");
    }
}

// Finish by removing touches, handling double-tap requests
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    [self updateOriginalTransformForTouches:[event touchesForView:self]];
    [self removeTouchesFromCache:touches];

    for (UITouch *touch in touches) {
        if (touch.tapCount >= 2) {
            [self.superview bringSubviewToFront:self];
        }
    }

    NSMutableSet *remainingTouches = [[[event touchesForView:self] mutableCopy] autorelease];
    [remainingTouches minusSet:touches];
    [self cacheBeginPointForTouches:remainingTouches];
}// Redirect cancel to ended
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{
    [self touchesEnded:touches withEvent:event];
}

2 个答案:

答案 0 :(得分:1)

您是否在询问如何确定视图的rect在当前坐标系中的位置?如果是的话,

CGRect transformedFrame = CGRectApplyAffineTransform(self.frame, incrementalTransform);

答案 1 :(得分:0)

好的,我想回答我自己的问题

昨晚我一直在寻找各种方法来执行我的大头钉我发现PanGestures对于我的任务会更方便

所以here是我使用它的链接

它对我有用