添加到 UIImageView 时 UIButton 没有响应

编程入门 行业动态 更新时间:2024-10-28 05:17:07
本文介绍了添加到 UIImageView 时 UIButton 没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试向具有透明背景的 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 没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 03:52:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184029.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UIImageView   UIButton

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!