我一直在試圖通過努力讓劉某動畫,只有當他被觸摸到的教程擴展。然而,觸摸甚至沒有被註冊,我相信它與它是一個子視圖有關。這裏是我的代碼:如何檢查我的子視圖是否被觸摸?
-(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的比較式‘結構的UIImage *’和‘結構的UIView *’缺乏投」我究竟做錯了什麼?