2つの画像を取り込む小さなアプリを作成したいので、画像をドラッグ可能にしたいと思っています。iPhone SDKで画像を1つだけドラッグする方法
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[ event allTouches] anyObject];
image.alpha = 0.7;
if([touch view] == image){
CGPoint location = [touch locationInView:self.view];
image.center = location;
}
それは動作しますが、問題は、画像がその中心からドラッグ可能であると私はそれを望んでいないということです。 の研究の後、私はこの解決策を見つけました。 だから私は別の解決策が見つかりました:それは非常によく動作しますが、私は別の画像を追加するときに、ビューのすべての画像を同時にドラッグ可能です
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
// Retrieve the touch point
CGPoint pt = [[touches anyObject] locationInView:self.view];
startLocation = pt;
[[self view] bringSubviewToFront:self.view];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
// Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:self.view];
frame = [self.view frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self.view setFrame:frame];
}
を。私はiPhone開発の初心者です。どのようにイメージをドラッグ可能にすることができるのか分かりません。
startLocationとは何ですか? –
** startLocation **は、** CGPoint **タイプのグローバル変数です。 – TheTiger