iphone - UIScrollView 上的 UIImageView 上的 UIButton(不工作)

标签 iphone ios uibutton

我在 UIScrollView 上的 UIImageView 上有 UIButton。但是,按钮不工作(按钮不响应它并写了 button.userInteractionEnabled = YES)。为什么?

pagingView = [[InfinitePagingView alloc] initWithFrame:CGRectMake(0.f, 0.f,            self.view.frame.size.width, self.view.frame.size.height - naviBarHeight)];
pagingView.delegate = self;
[self.view addSubview:pagingView];

UIImage *image1 = [UIImage imageNamed:[NSString stringWithFormat:@"1.jpg"]];
page1 = [[UIImageView alloc] initWithImage:image1];
page1.frame = CGRectMake(0, 0, pagingView.frame.size.width * 0.8, pagingView.frame.size.height * 0.8);
page1.userInteractionEnabled = YES;
page1.contentMode = UIViewContentModeScaleAspectFit;

btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 200, 50, 50);
[btn addTarget:self action:@selector(toControl) forControlEvents:UIControlEventTouchUpInside];
[page1 addSubview:btn];
[pagingView addPageView:page1];

最佳答案

尝试使用以下内容:

page1.userInteractionEnabled = NO;
btn.userInteractionEnabled = YES;

还要确保您的按钮没有超出 ImageView 的框架。 还有一件事,为什么不直接将按钮添加到 View 而不是 ImageView 。

关于iphone - UIScrollView 上的 UIImageView 上的 UIButton(不工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16849007/

相关文章:

iphone - 以编程方式更改按钮的属性

iphone - 如何创建新的CMAttitude引用系以使重力位于Y轴上

iphone - 从不兼容类型 'id<MFMessageComposeViewControllerDelegate>' 分配给 'MainViewController *'

ios - 在我的任何代码运行之前,iOS Keyboard Extension崩溃

iphone - 检查NSString是否包含base64数据

iphone - 如何在两个 UIButton 选择器之间切换

C makefile 直接在iphone上编译OpenGL项目

android - Firebase AB 测试 iOS 用户定位应用程序版本不起作用

ios - IOS Weird编译器错误:“expected']'before;'在单例中对NSString常量使用set-ter

swift - 通过点击更改 UIButton 的图像 - Swift