我已准备好并检查了GitHub a simple test case,以便拖动自定义UIView
:
效果很好,拖拽在Tile.m中实现为:
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
CGPoint previous = [touch previousLocationInView:self];
self.frame = CGRectOffset(self.frame,
(location.x - previous.x),
(location.y - previous.y));
}
然而,瓷砖对于my actual game来说太大了(一旦UIScrollView
中的游戏板被放大,我将不得不调整它们的缩放比例):
所以我通过调用
来缩放我的自定义UIView
tile.transform = CGAffineTransformMakeScale(.5, .5);
尺寸会发生变化,但瓷砖会根据需要“快速”拖动两倍:
可能应该调整touchesMoved
代码(上面的代码),但是我不确定transform
操作会破坏什么?
答案 0 :(得分:0)
没关系,我找到了解决方案:
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
CGPoint previous = [touch previousLocationInView:self];
if (!CGAffineTransformIsIdentity(self.transform)) {
location = CGPointApplyAffineTransform(location, self.transform);
previous = CGPointApplyAffineTransform(previous, self.transform);
}
self.frame = CGRectOffset(self.frame,
(location.x - previous.x),
(location.y - previous.y));
}