今天做的项目需要通过自定义的导航栏中添加一个UIImagePickerViewControlle,但是添加之后发现无法正常显示导航栏的取消按钮无反应。后来通过查明,其实是内部实现了一些可以用的代理方法,只是没有去调用而已。具体的详情可以看用UIImagePickerViewController自定义相机界面 http://blog.sina.com.cn/s/blog_aedec703010181sh.html
现总结几个方法如下:
1.单点击取消按钮的时候会调用一下的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
NSLog(@"点击了取消按钮");
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
3.也是最苦人的一点,因为以为是系统的控制器无法调用,所以想不到方法去修改,其实以下的方法中可以使用- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
然后我把具体的方法实现发表如下吧:- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
NSLog(@"点击了取消按钮");
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplicationsharedApplication] setStatusBarHidden:NO];
[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
UIView *custom = [[UIViewalloc] initWithFrame:CGRectMake(0,0,0,0)];
UIBarButtonItem *btn = [[UIBarButtonItemalloc] initWithCustomView:custom];
[viewController.navigationItem setRightBarButtonItem:btn animated:NO];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
{
UIImage *originImage = [infovalueForKey:UIImagePickerControllerEditedImage];
CGSize cropSize;
cropSize.width = 180;
cropSize.height = cropSize.width * originImage.size.height / originImage.size.width;
NSDate *date = [NSDatedate];
NSDateFormatter *formatter = [[NSDateFormatteralloc] init];
[formatter setDateFormat:@"yyyyMMddHHmmss"];
originImage = [originImage imageByScalingToSize:cropSize];
NSData *imageData = UIImageJPEGRepresentation(originImage, 0.9f);
NSString *uniqueName = [NSStringstringWithFormat:@"%@.jpg",[formatterstringFromDate:date]];
NSString *uniquePath = [kDocumentsPathstringByAppendingPathComponent:uniqueName];
NSLog(@"uniquePath: %@",uniquePath);
[imageData writeToFile:uniquePath atomically:NO];
NSLog(@"Upload Image Size: %u KB",[imageData length] /1024);
[picker dismissViewControllerAnimated:YEScompletion:^{
[self.delegaterefleshWithfaceData:originImage];
NSLog(@"originImage==================%@",originImage);
}];
}
}