我一直试图通过尝试让 Ryu 仅在他被触摸时动画来扩展教程。但是,触摸甚至没有被注册,我相信它与它是一个子视图有关。这是我的代码:
-(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类型'struct UIImage *'和'struct UIView *'的比较缺少演员表。” 我究竟做错了什么?