iOS:调用dismissModalViewController后屏幕不再接收触摸
<p><p>我有两种观点。非常简单的设置只是为了玩相机胶卷。</p>
<p>一个 View 将使用以下方法调出相机胶卷:</p>
<pre><code>;
</code></pre>
<p>由 <code>UIButton</code> 触发。它打开了摄像头,一切都很好。</p>
<p>拍照后,我正在调用以下命令来关闭 Controller :</p>
<pre><code>;
</code></pre>
<p>再次,一切正常。</p>
<p>但在模态视图关闭后,调出 <code>imagePicker</code>Controller 的 View 不再接收触摸(<code>UIButton</code> 将不再再次调出相机)。</p>
<p>只有当我切换到另一个 View 并返回时,它才会再次开始接收触摸。</p>
<p>我一直在寻找解决此问题的方法,但没有成功找到任何东西。提前致谢。</p>
<p>编辑(添加代码):</p>
<p><strong>在 CameraController.m 中</strong> </p>
<p><strong>这是调出相机胶卷的地方</strong></p>
<p>(<code>UIViewController</code> 的子类符合
<code><UIImagePickerControllerDelegate, UINavigationControllerDelegate></code>)</p>
<pre><code>//UIButton that brings up the imagePicker
- (IBAction)useCamera
{
;
;
}
//Initializing ImagePicker
- (void)prepareImagePicker
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
self.imagePicker = [ init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = ;
self.imagePicker.delegate = self;
OverlayCameraView *cameraOverlay = [ initWithFrame:(CGRect){{0, 0}, 320, 480} andTheCameraController:self];
self.imagePicker.cameraOverlayView = cameraOverlay;
}
}
//Delegate Method when a picture is taken
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.imagePicker.delegate = nil;
;
self.imagePicker = nil;
self.imageView.image = ;
}
</code></pre>
<p><strong>在 OverlayCameraView.m</strong></p>
<pre><code>//Camera Overlay Class (Subclass of UIView)
- (id)initWithFrame:(CGRect)frame andTheCameraController:(CameraController*)cameraController
{
if ((self = ))
{
self.camera = cameraController;
//.…2 UIButtons set up
}
return self;
}
//Overlay Cancel Button
- (void) cancel
{
;
}
//Overlay Take Picture Button
- (void) takeAPicture
{
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该通过 <code>UIImagePickerControllerDelegate</code> 方法在选择器上调用 <code>dismissViewControllerAnimated</code> 而不是 <code>self</code>。</p>
<pre><code>;
</code></pre>
<p>或者如果您保留对它的引用:</p>
<pre><code>;
</code></pre>
<p>编辑:</p>
<p>根据修改后的代码,我相信</p>
<pre><code>self.imagePicker.cameraOverlayView = cameraOverlay;
</code></pre>
<p>应该是:</p>
<pre><code>self.imagePicker.cameraOverlayView = cameraOverlay.view;
</code></pre>
<p>如果您不使用 ARC,这也会导致 +2 引用计数并且会泄漏:</p>
<pre><code>self.imagePicker = [ init];
</code></pre>
<p>应该是为了正确的引用计数:</p>
<pre><code>UIImagePickerController *picker = [ init];
self.imagePicker = picker;
;
</code></pre></p>
<p style="font-size: 20px;">关于iOS:调用dismissModalViewController后屏幕不再接收触摸,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19412878/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19412878/
</a>
</p>
页:
[1]