タッチを使用してさまざまな画像をドラッグできるようにしようとしています。これまでのところ、1 つの画像だけで機能するようにしようとしていますが、機能していません (つまり、指で画像を移動できません)。私は何を間違っていますか?
次のコードを含むファイルがいくつかあります。
DragView.h
@interface DragView : UIImageView {
}
@end
DragView.m
#include "DragView.h"
@implementation DragView
- (void)touchesMoved:(NSSet *)set withEvent:(UIEvent *)event {
CGPoint p = [[set anyObject] locationInView:self.superview];
self.center = p;
}
@end
ViewController.h
#import <UIKit/UIKit.h>
#import "DragView.h"
@interface ViewController : UIViewController {
}
@property (nonatomic, strong) DragView *basketView;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize basketView;
- (void)viewDidLoad
{
[super viewDidLoad];
basketView = [[DragView alloc]
initWithImage:[UIImage imageNamed:@"basket.png"]];
basketView.frame = CGRectMake(140, 340.2, 60, 30);
[self.view addSubview:basketView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end