虹膜动画在[UIImagePickerController viewDidAppear]
方法上触发。苹果公司不鼓励为各种原因而子类化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];
[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
。