当用户登陆页面时,我有一个类型为相机的UIImagePickerController。我在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");
}
答案 0 :(得分:4)
问题在于这一行:
self.overlayView.frame = self.cameraOverlayView.frame;
我们cameraOverlayView
为零;它没有框架,因为它甚至还没有存在。所以我们给overlayView
一个零帧。它是无量纲的。出现按钮,但它有一个零大小的超视图,因此无法点按。
现在,您可能会问,为什么?这是因为iOS中的触摸传递方式。要进行可触摸,子视图的超级视图也必须是可触摸的,因为超级视图在子视图之前经过了触摸测试。但零大小的视图是不可触摸的:你的触摸错过了overlayView
,所以它也错过了按钮。
解决方案可能就像给overlayView
一个合理的实际框架一样简单。 时也可能 }),但无论如何这是开始的地方。