Problem with Touch-Events after pushing ViewController
All touch-events are recogniced perfectly before I push my programmatically created ViewController. I think there is no connection between the new ViewController and my code.
That's my code where i push the ViewController:
UIViewController *detail = [[UIViewController alloc] init];
CGRect frame = CGRectMake(0, -44, 320, 411);
UIView *galleryView = [[UIView alloc] initWithFrame:frame];
UIImageView *galleryImageView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
galleryImageView.image = [UIImage imageNamed:@"bg.png"];
[galleryView addSubview:galleryImageView];
detail.view = galleryView;
frame = CGRectMake(0, 0, 320, 367);
int height = (([photo_id count] - 1) / 3);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];
scrollView.contentSize = CGSizeMake(320, (height * 102) + 12);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScr开发者_运维知识库ollIndicator = NO;
scrollView.scrollsToTop = NO;
[galleryView addSubview:scrollView];
int z = 0;
for (int x = 0; x < ([photo_id count] / 3); x++) {
for (int y = 0; y <= 2; y++) {
frame = CGRectMake((y * 90) + (y * 12) + 18, (x * 90) + (x * 12) + 18, 76, 76);
AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:frame];
frame = CGRectMake((y * 90) + (y * 12) + 12, (x * 90) + (x * 12) + 12, 90, 90);
UIImageView *borderView = [[UIImageView alloc] initWithFrame:frame];
NSString *flickrURL = [photo_secret objectAtIndex:z];
NSURL *url = [NSURL URLWithString:flickrURL];
imageView.backgroundColor = [UIColor whiteColor];
imageView.opaque = NO;
imageView.contentMode = UIViewContentModeScaleAspectFill;
[borderView setUserInteractionEnabled:YES];
borderView.tag = z;
NSLog([NSString stringWithFormat:@"%i", borderView.tag]);
[imageView loadImageFromURL:url];
borderView.image = [UIImage imageNamed:@"img_border.png"];
z++;
[scrollView addSubview:imageView];
[scrollView addSubview:borderView];
}
}
[self.navigationController pushViewController:detail animated:YES];
Touch-Events are logged with following code:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Hinweis" message:[NSString stringWithFormat:@"%d", touch.view.tag] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[errorAlert show];
NSLog([NSString stringWithFormat:@"%i", touch.view.tag]);
}
I found the solution: Subclass the UIScrollView and add touchEventHandling.
精彩评论