我正在使用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行为的任何变化。
感谢您的帮助,