私はhttp://www.raywenderlich.com/33806/how-to-make-a-letterword-game-with-uikit-part-2に取り組んでおり、ビューを参照して次を追加するように言っています実装:
int _xOffset, _yOffset;
初期化子の場合:
self.userInteractionEnabled = YES;
また、ドラッグを処理するために実装する 3 つのメソッドも提供します。
#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];
}
ただし、画像の1つに触れてドラッグしようとしても、何も起こらないようです。絶対に動かないようです。
これよりも多くの作業があります。ドラッグした画像がドロップされた場所に基づいて、特定のことをしたい。しかし、現在スモーク テストに取り組んでおり、このコードを追加したときと比べて UI の動作に変化は見られません。
助けてくれてありがとう、