简体   繁体   中英

Hide Shutter in UIImagePickerController

I have designed an iris shutter animation for a camera view in an iPhone app.

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.

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. 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. 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:

- (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". 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. 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
  2. PLCameraViewIrisAnimationDidEndNotification - iris animation is completed.

And the usage is straightforward: call UIGetScreenImage() on 1st notification, render grabbed image on screen (fullscreen) just above the 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:

-(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. Play with some values of a_iMsToDelay.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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