リュウが触れられたときだけアニメートするようにして、チュートリアルを拡張しようとしています。ただ、タッチも登録されておらず、サブビューと関係があると思います。これが私のコードです:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if([touch view] == ryuView){
NSLog(@"Touch");
} else {
NSLog(@"No touch");
}
}
-(void) ryuAnims{
NSArray *imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
nil];
ryuView.animationImages = imageArray;
ryuView.animationDuration = 1.1;
[ryuView startAnimating];
}
-(void)viewDidLoad {
[super viewDidLoad];
UIImageView *image = [[UIImageView alloc] initWithFrame:
CGRectMake(100, 125, 150, 130)];
ryuView = image;
ryuView.image = [UIImage imageNamed:@"1.png"];
ryuView.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:ryuView];
[image release];
}
このコードは正常にコンパイルされますが、ryuをタッチまたはクリックしても、何も起こりません。私も試しました
if([touch view] == ryuView.image)
しかし、それは私にこのエラーを与えます:「異なるObjective-Cタイプの比較'structUIImage*'と'structUIView*'にはキャストがありません。」私は何が間違っているのですか?