本文介绍了添加到 UIImageView 时 UIButton 没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向具有透明背景的 UIImageView 添加一个按钮 - 该按钮显示正常但没有响应.(不调用takePictureClicked)
I'm trying to add a button to a UIImageView with a transparent background - the button is shown ok but is not responding. (takePictureClicked is not called)
我的代码:
cameraController = [[UIImagePickerController alloc] init];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.delegate = self;
cameraController.allowsEditing=YES;
cameraController.showsCameraControls = NO;
cameraController.navigationBarHidden = YES;
cameraController.toolbarHidden = YES;
// overlay on top of camera lens view
UIImageView *cameraOverlayView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"camera_overlay.png"]];
cameraOverlayView.alpha = 0.0f;
//Take picture button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *btnImage = [UIImage imageNamed:@"714-camera.png"];
[button setImage:btnImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(takePictureClicked) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(cameraOverlayView.center.x-16,cameraOverlayView.frame.size.height,32,32);
[cameraOverlayView addSubview:button];
[cameraOverlayView setUserInteractionEnabled:YES];
[cameraOverlayView bringSubviewToFront:button];
cameraController.cameraOverlayView = cameraOverlayView;
推荐答案
您是否尝试将 userInteractionEnabled
设置为 UIImageView
?
Have you tried setting userInteractionEnabled
to the UIImageView
?
尝试:
cameraOverlayView.userInteractionEnabled = YES;
这篇关于添加到 UIImageView 时 UIButton 没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!