【发布时间】:2011-09-04 02:17:09
【问题描述】:
我有一个滚动视图,它有一个带有图像作为子视图的图像视图,并且图像视图有一个 UIButton 作为其子视图之一。问题是,我无法点击按钮。我可以看到按钮,但我无法点击它。
谁能告诉我我搞砸了什么?任何帮助是极大的赞赏!谢谢!
下面是代码:
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.jpg"]];
scrollView.delegate = self;
self.view = scrollView;
// add invisible buttons
[self addInvisibleButtons];
[scrollView addSubview:imageView];
addInvisibleButtons 的代码如下:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonHandler) forControlEvents:UIControlEventAllEvents];
[button setTitle:@"point" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
[self.imageView addSubview:button];
【问题讨论】:
-
您可以尝试看看bringSubviewToFront: 在将按钮添加到图像视图后是否有效?或者同样可以应用于滚动视图中的图像视图。
-
事实上,我试过了,但没有成功。 userInteractionEnabled 成功了。
标签: ios objective-c cocoa-touch uiimageview uibutton