简体   繁体   English

在UIImagePickerController中隐藏快门

[英]Hide Shutter in UIImagePickerController

I have designed an iris shutter animation for a camera view in an iPhone app. 我已经为iPhone应用程序中的相机视图设计了虹膜快门动画。

Unfortunately, it seems impossible to hide Apple's shutter when the view appears, even if I hide the camera controls and create a custom cameraOverlayView. 不幸的是,即使我隐藏了相机控件并创建了一个自定义的cameraOverlayView,在显示视图时也无法隐藏Apple的快门。

I have gotten around this by animating my shutter on top of the normal shutter when the view appears, using the viewWillAppear and viewDidAppear methods of UIImagePickerController. 通过使用UIImagePickerController的viewWillAppear和viewDidAppear方法在视图出现时将快门设置在普通快门上方,可以解决此问题。 However, I can't get the shutter to be hidden under my shutter the first time through. 但是,我无法让快门第一次被隐藏在快门之下。 When the app launches, it shows a camera view, and the original shutter is visible. 应用启动时,它会显示相机视图,并且可以看到原始快门。 On all subsequent views of the cameraController, my workaround works. 在cameraController的所有后续视图上,我的解决方法都可以工作。 Any suggestions? 有什么建议么?

Here's my code. 这是我的代码。 This is from my app delegate: 这来自我的应用程序委托:

- (void)applicationDidFinishLaunching:(UIApplication *)application {   

  cameraController = [[CameraController alloc] initWithMode:@"camera"];
  [window addSubview:cameraController.view];

}

And this is from my UIImagePickerController subclass: 这来自我的UIImagePickerController子类:

- (void) viewWillAppear:(BOOL)animated {

  if (self.sourceType != UIImagePickerControllerSourceTypePhotoLibrary || simulatorView) {
    [self addShutter];
    [shutter close];
  }   
  [super viewWillAppear:animated];

}


- (void) viewDidAppear:(BOOL)animated {

  if (self.sourceType != UIImagePickerControllerSourceTypePhotoLibrary || simulatorView) {
    [shutter openShutter:.5f];
  }
  [super viewDidAppear:animated];

}

Note that the docs say that subclassing UIImagePickerController isn't supported, so it may work in some cases but isn't "safe". 请注意,文档说不支持对UIImagePickerController的子类化,因此在某些情况下它可以工作,但并不“安全”。 Not sure if it would get rejected by the app store. 不知道它是否会被应用商店拒绝。 (Probably depends on how picky their static code verification tool is.) (可能取决于他们的静态代码验证工具有多挑剔。)

I don't really have a good answer, but you might try either 1) iterating over the subviews of the picker's main view to see if you can identify whatever is being used to animate the shutter, then mangle it so that it won't display, or 2) for the initial animation, just show the initial image picker main view under another opaque black view. 我的回答不是很好,但是您可以尝试以下两种方法之一:在选择器主视图的子视图上进行迭代,以查看是否可以识别出用于动画快门的内容,然后对其进行处理以使其不会显示,或2)对于初始动画,只需在另一个不透明的黑色视图下显示初始图像选择器主视图即可。 Not sure if the user-specified overlay view would work for that or not, but you might be able to do those without subclassing. 不知道用户指定的重叠视图是否可以使用,但是您可以在不进行子类化的情况下进行操作。

Searching for undocumented subviews is another thing that's theoretically unsafe though since who knows how the implementation might change in the future. 从理论上讲,搜索未记录的子视图是另一件事,尽管这是不安全的,因为谁知道将来实现会如何变化。

Possibly too late, but my proposal is to use the following notifications (found while debugging) 可能为时已晚,但是我的建议是使用以下通知(在调试时找到)

  1. PLCameraControllerAvailable - camera controller object is initiated, but shutter is not visible yet PLCameraControllerAvailable-相机控制器对象已启动,但尚不可见快门
  2. PLCameraViewIrisAnimationDidEndNotification - iris animation is completed. PLCameraViewIrisAnimationDidEndNotification-虹膜动画已完成。

And the usage is straightforward: call UIGetScreenImage() on 1st notification, render grabbed image on screen (fullscreen) just above the UIImagePicker. 而且用法很简单:在第一个通知上调用UIGetScreenImage(),在UIImagePicker上方的屏幕(全屏)上渲染抓取的图像。 Destroy rendered image on the 2nd notification. 销毁第二个通知上的渲染图像。

I try the same thing with no results, so I do this workaround: 我尝试同样的事情但没有结果,所以我执行以下解决方法:

1- Suppose you have a method called showAllButtons with no parameters that will show all your custom things (buttons, tool bars,...) 2- Initialize all the custom controls hidden 3- Write a method that will call the last function but within an interval: 1-假设您有一个名为showAllButtons的方法,该方法没有任何参数,它将显示所有自定义内容(按钮,工具栏等)。2-初始化所有隐藏的自定义控件; 3-编写一个将调用最后一个函数但位于内部的方法。间隔:

-(void)showAllButtonsDelayed:(NSTimeInterval)a_iMsToDelay
{
    NSTimer* tmpShowButtonsTimer = [NSTimer timerWithTimeInterval:a_iMsToDelay target:self selector:@selector(showAllButtons) userInfo:nil repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:tmpShowButtonsTimer forMode:NSDefaultRunLoopMode];
}

4- Call that method in the willDidAppear method of the UIImagePickerController subclass. 4-在UIImagePickerController子类的willDidAppear方法中调用该方法。 Play with some values of a_iMsToDelay. 播放一些a_iMsToDelay值。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM