虹膜动画在[UIImagePickerController viewDidAppear] 方法上触发。 Apple 出于各种原因不鼓励子类化 UIImagePickerController,但如果您需要在虹膜动画完成后添加叠加层并且不愿意使用 AVFoundation 编写自己的图像捕获类,我会这样做:
如果您还没有,请添加一个新的 UITabBarViewController 子类,其中包含 UIImagePickerController @property 和 UIImagePickerControllerDelegate 和 UINavigationControllerDelegate 的委托
@interface my_TabBarViewController : UITabBarController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIImagePickerController *picker;
在实现中,添加一个initCamera 方法并在您的viewDidLoad 中调用它
- (void)initCamera
{
_picker = [[UIImagePickerController alloc] init];
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
_picker.view.frame = CGRectMake(0.f, 20.f, 320.f, 499.f);
_picker.navigationBarHidden = TRUE;
_picker.delegate = self;
_picker.cameraOverlayView = YourCameraOverlayView;
[self.view addSubview:_picker.view];
[_picker viewDidAppear:FALSE];
[self.view sendSubviewToBack:_picker.view];
}
然后当你的相机视图标签栏项目被点击时,在你的标签栏控制器上使用这样的方法显示相机:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(@"tapped: %@", item.title);
if ([item.title isEqualToString:@"Camera"]) {
[self.view bringSubviewToFront:_picker.view];
} else {
[self.view sendSubviewToBack:_picker.view];
}
}
最后,在标签栏控制器上的 UIImagePickerController 委托方法中,清理图像选择器,并将信息字典发送到相机视图控制器以处理图像,但您需要:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[_picker.view removeFromSuperview];
yourCameraViewController *camVC = (yourCameraViewController*)[self.viewControllers objectAtIndex:1];
// Index 1 would just be the second tab, adjust accordingly
[camVC imagePickerController:picker didFinishPickingMediaWithInfo:info];
[self initCamera];
}
在这里对[self initCamera]; 的调用将重新初始化UIImagePickerController,您可能想也可能不想在这里做。我可能会在您的yourCameraViewController 中只使用#import "my_TabBarViewController.h,然后您可以通过调用在您的UIImagePickerController 委托方法中获取指向picker 的指针:
my_TabBarViewController *tabBarVC = (my_TabBarViewController*)self.tabBarController;
并让yourCameraViewController 将其关闭并发送消息tabBarVC 以在您再次需要它时重新初始化UIImagePickerController。