Rav*_*avi 31 cocoa-touch objective-c uibutton uiimageview ios
我有一个滚动视图,它有一个图像视图,图像作为子视图,图像视图有一个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];
Run Code Online (Sandbox Code Playgroud)
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];
Run Code Online (Sandbox Code Playgroud)
Dee*_*olu 93
UIImageView已默认userInteractionEnabled设置为NO/ false.
您将按钮作为子视图添加到图像视图.你应该将它设置为YES/ true.