我正在使用http://www.raywenderlich.com/33806/how-to-make-a-letterword-game-with-uikit-part-2,它参考了添加以下内容的视图实施:
int _xOffset, _yOffset;
对于初始化器:
self.userInteractionEnabled = YES;
它还提供了三种方法来实现处理拖动:
#pragma mark - dragging the tile
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint pt = [[touches anyObject] locationInView:self.superview];
_xOffset = pt.x - self.center.x;
_yOffset = pt.y - self.center.y;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint pt = [[touches anyObject] locationInView:self.superview];
self.center = CGPointMake(pt.x - _xOffset, pt.y - _yOffset);
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event];
}
但是,当我触摸其中一张图像并尝试拖动它时,似乎什么也没有发生。它似乎永远不动。
还有比这更多的工作要做;我想根据拖放图像的位置做一些特定的事情。但是现在我正在进行冒烟测试,当我添加此代码时,我看不到 UI 行为的任何变化。
谢谢你的帮助,