UIImageView のサブクラスであるクラス Box を作成しました。
私のプログラムでは、Box をメイン ビュー コントローラーで唯一のドラッグ可能なオブジェクトにしたいと考えています。
これが私のコードです:
BoxViewController.m
-(void) viewDidLoad{
[super viewDidLoad];
target = [[Box alloc] initWithFrame:CGRectMake(10,10,100,100)];
[self.view addSubView:target];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == target){
CGPoint location = [touch locationInView:self.view];
target.center = location;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[self touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event];
}
条件がうまくいっていないと思いますが、isKindOfClass を試してみました。どちらも機能しませんでした。解決策は何ですか?どうもありがとうございました。