UIImagePickerController Overlay Buttons Not Firing

丶灬走出姿态 提交于 2019-11-29 15:42:02

The problem is this line:

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

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!