UIImagePickerController叠加按钮不会触发 [英] UIImagePickerController Overlay Buttons Not Firing

查看:108
本文介绍了UIImagePickerController叠加按钮不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户登陆页面时,我有一个类型为相机的UIImagePickerController。我在UIImagePickerController的顶部放置了一个自定义相机覆盖,但没有一个按钮事件被触发。我知道这些代码大部分来自基本的Apple代码,所以我对发生的事情感到困惑。

I have a UIImagePickerController of type camera when the user lands on a page. I have put a custom camera overlay on top of the UIImagePickerController, but none of the button events are firing. I know most of this code is from a base Apple code, so I am perplexed as to what is happening.

@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中的代码在下面,其中没有日志被触发:

The CameraOverlay's owner is TakePhotoViewController. One of the buttons inside of the CameraOverlay sends a Touch Up Inside event to the outlet function listed below. The code in the TakePhotoViewController attached to a button is below, of which no logs are firing:

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


推荐答案

问题是这一行:

self.overlayView.frame = self.cameraOverlayView.frame;

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

Our cameraOverlayView is nil; it has no frame, because it doesn't even exist yet. So we are giving the overlayView a zero frame. It is dimensionless. The button appears, but it has a zero-sized superview and therefore cannot be tapped.

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

Now, you may ask, why is that? It's because of the way touch delivery works in iOS. To be touchable, a subview's superview must also be touchable, because the superview is hit-tested for the touch before the subview. But a zero-size view is not touchable: your touch misses the overlayView, so it misses the button as well.

解决方案可能就像给出 overlayView 一个合理的实际框架一样简单。 c> viewWillAppear:),但无论如何这都是开始的地方。

The solution might be as simple as giving the overlayView a reasonable real frame. There may also be timing problems about when you do that (e.g. it may be that you cannot really set the frame until the image picker is about to appear - viewWillAppear:), but in any case this is the place to start.

这篇关于UIImagePickerController叠加按钮不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆