ios – UIImagePickerController叠加按钮不触发

前端之家收集整理的这篇文章主要介绍了ios – UIImagePickerController叠加按钮不触发前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
用户登陆页面时,我有一个类型为相机的UI ImagePickerController.我在UIImagePickerController的顶部放置了一个自定义相机覆盖,但没有一个按钮事件被触发.我知道这些代码大部分来自基本的Apple代码,因此我对发生的事情感到困惑.
@interface TakePhotoViewController : UIImagePickerController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
...

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if (self.capturedImages.count > 0)
{
    [self.capturedImages removeAllObjects];
}

self.sourceType = sourceType;
self.delegate = self;

if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
    /*
     The user wants to use the camera interface. Set up our custom overlay view for the camera.
     */
    self.showsCameraControls = NO;

    /*
     Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file,so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view,and set self's reference to the view to nil.
     */
    [[NSBundle mainBundle] loadNibNamed:@"CameraOverlay" owner:self options:nil];
    float scale = [self getScaleForFullScreen];
    self.cameraViewTransform = CGAffineTransformMakeScale(scale,scale);
    self.overlayView.frame = self.cameraOverlayView.frame;
    self.cameraOverlayView = self.overlayView;
    self.overlayView = nil;
}

}

CameraOverlay的所有者是TakePhotoViewController. CameraOverlay内部的一个按钮将Touch Up Inside事件发送到下面列出的插座功能.连接到按钮的TakePhotoViewController中的代码位于下方,其中没有日志触发:

- (IBAction)outlet:(id)sender {
NSLog(@"outlet");
}

解决方法

问题是这一行:
self.overlayView.frame = self.cameraOverlayView.frame;

我们的cameraOverlayView是零;它没有框架,因为它甚至还没有存在.所以我们给overlayView一个零帧.它是无量纲的.出现按钮,但它有一个零大小的超视图,因此无法点按.

现在,您可能会问,为什么?这是因为iOS中的触摸传递方式.要进行可触摸,子视图的超级视图也必须是可触摸的,因为超级视图在子视图之前经过了触摸测试.但零大小的视图是不可触摸的:你的触摸错过了overlayView,所以它也错过了按钮.

解决方案可能就像给overlayView一个合理的实际框架一样简单.关于何时这样做可能还存在时间问题(例如,在图像选择器即将出现之前,您可能无法真正设置框架 – viewWillAppear :),但无论如何这都是开始的地方.

原文链接:https://www.f2er.com/iOS/335629.html

猜你在找的iOS相关文章