我正在尝试向具有透明背景的UIImageView添加按钮 - 按钮显示正常但没有响应。 (没有调用takePictureClicked)
我的代码:
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;
答案 0 :(得分:0)
通常您会创建一个UIView
,您可以在其中添加UIButton
或UIImageView
等不同的ui元素。 UIImageView
仅用于UIImages
,而不是用于添加任何其他内容。创建另一个UIView
,其中包含其中的所有元素。
Like this post describes,即使Interface Builder
也不允许您向UIButton
添加UIImageView
。
答案 1 :(得分:0)
您必须能够进行用户互动:
[cameraOverlayView setUserInteractionEnabled:YES];
如果您正在使用它,还可以使用Interface Builder中的复选框。
这是必需的,因为对于默认,UIImageView
具有用户互动disabled
。
答案 2 :(得分:0)
您是否尝试将userInteractionEnabled
设置为UIImageView
?
尝试:
cameraOverlayView.userInteractionEnabled = YES;