我已经用图像和 tapGestures 实现了 2 个 ImageView,这很好用,现在我想根据我点击的图像切换到另一个 ViewController。我不知道如何声明我的 ImageView 它应该调用哪个 ViewController。
所以我的代码是:
-(void) initImageViews{
self.navigationItem.title = @"Menu";
UIImage *serviceImage = [UIImage imageNamed:@"Service.png"];
self.serviceImageView = [[UIImageView alloc] initWithImage:serviceImage];
[self.serviceImageView setFrame:CGRectMake(20, 20, 48,48 )];
[self.view addSubview:self.serviceImageView];
[self.view setBackgroundColor:[UIColor blackColor]];
UIImage *industryImage = [UIImage imageNamed:@"Industry.png"];
self.industryImageView = [[UIImageView alloc] initWithImage:industryImage];
[self.industryImageView setFrame:CGRectMake(73,20,48,48)];
[self.view addSubview:industryImageView];
UITapGestureRecognizer *singleTap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[self.industryImageView setUserInteractionEnabled:TRUE];
[self.serviceImageView setUserInteractionEnabled:TRUE];
[self.serviceImageView addGestureRecognizer:singleTap];
[self.industryImageView addGestureRecognizer:singleTap];
}
- (void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer {
NSLog(@"Tapped!");
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Service"]) {
SelectOptionViewController *controller = (SelectOptionViewController*)segue.destinationViewController;
}if ([segue.identifier isEqualToString:@"Industry"]) {
SelectOptionViewController *controller = (SelectOptionViewController*)segue.destinationViewController;
}
}
}
提前致谢 :)