Проблема с Touch-Events после нажатия ViewController - PullRequest
0 голосов
/ 27 июля 2010

Все сенсорные события распознаются до того, как я запускаю свой программно созданный ViewController.Я думаю, что нет никакой связи между новым ViewController и моим кодом.

Это мой код, в который я помещаю 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.showsVerticalScrollIndicator = 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];

События касания регистрируются следующим кодом:

- (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]);   
}

1 Ответ

0 голосов
/ 16 августа 2010

Я нашел решение: подкласс UIScrollView и добавить touchEventHandling.

...