【问题标题】:UIButton doesn't interact in UIScrollViewUIButton 在 UIScrollView 中不交互
【发布时间】:2010-11-27 03:38:40
【问题描述】:

我有一个窗口(例如,不是全屏)UIScrollView(在UIView 内)滚动浏览UIImageViews 组和UIButtons(想法是你点击按钮做某事与显示的图像)。 UIButton 确实会发生任何触摸事件 - 我该如何解决?

我已阅读 thisthisthisthisthis - 但我要么不明白答案或其含义,要么并不真正相关。

NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
    Sentence *testSentence = [[managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:i];
    //NSLog(@"testSentence: %@", testSentence);

    //NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
    //Your going to need to optimise this by creating another thumbnail image to use here.

    NSArray *paths       = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *imageName = [[paths objectAtIndex:0] stringByAppendingPathComponent:[testSentence image]];
    //NSLog(@"imageName: %@", imageName);

    UIImage *image = [[UIImage alloc] initWithContentsOfFile:imageName];
    //NSLog(@"image: %@", image);

    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    //NSLog(@"imageView: %@", imageView);

    [imageView setContentMode:UIViewContentModeScaleAspectFit];
    [imageView setBackgroundColor:[UIColor blackColor]];

    // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
    CGRect rect = imageView.frame;
    rect.size.height = kScrollObjHeight;
    rect.size.width = kScrollObjWidth;
    imageView.frame = rect;
    imageView.tag = i;  // tag our images for later use when we place them in serial fashion

    imageView.frame = rect;

    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [aButton setTitle:@"Play" forState:UIControlStateNormal];
    aButton.frame = CGRectMake(10, 10, 70, 70);
    [aButton setUserInteractionEnabled:YES];
    [aButton setEnabled:YES];
    [aButton setAlpha:1];

    UIView *buttonWrapperUIView = [[UIView alloc] init];

    [aButton addTarget:self action:@selector(clickPlay:) forControlEvents:UIControlEventTouchUpInside];

    [imageView addSubview:aButton];
    [imageView bringSubviewToFront:aButton];

    [scrollView1 addSubview:imageView];

    NSLog(@"aButton %@", aButton);

    [image release];
    [imageView release];
}

[self layoutScrollImages];  // now place the photos in serial layout within the scrollview

【问题讨论】:

    标签: iphone cocoa-touch uiscrollview uiimageview uibutton


    【解决方案1】:

    试试

    [imageView setUserInteractionEnabled:YES]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-15
      • 2012-11-08
      • 2015-10-07
      • 1970-01-01
      • 2012-04-16
      • 1970-01-01
      相关资源
      最近更新 更多