我使用手势触控功能旋转调整图像大小。现在我想做的是当图像碰到某个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];
}
答案 0 :(得分:1)
您是否在询问如何确定视图的rect在当前坐标系中的位置?如果是的话,
CGRect transformedFrame = CGRectApplyAffineTransform(self.frame, incrementalTransform);
答案 1 :(得分:0)