关于将系统自带的UIImagePickerController 作为uitabbarcontroller时 present时出现问题的解决

把我的代码先放上来吧: 

#pragma mark --

#pragma mark Methods

- (void)initImagePickerControllerInterface

{

    if (!_imagePickerController) {

        _imagePickerController = [[UIImagePickerControlleralloc]init];

    }

    

    [_imagePickerControllersetSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

    [_imagePickerControllersetDelegate:self];

    [_imagePickerControllersetAllowsEditing:NO];

    [selfaddChildViewController:_imagePickerController];    //只需要加上这句话即可解决present时页面突闪的问题

    [self.viewaddSubview:_imagePickerController.view];

    

    [[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

}



//注意:控制器还需要继承

UINavigationControllerDelegate

//下面这个用来解决都留有 20 个像素空隙的问题: (在当前类的viewwillappear和viewdidappear里不再需要设置statusbar)这样上边的状态栏会闪现一下,但没有更好的办法了

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

{

    

    [UIViewanimateWithDuration:0.4animations:^{   //这个地方设成0.3貌似就不行

        

        [[UIApplicationsharedApplication]setStatusBarHidden:YES];

        

    } completion:^(BOOL finished) {

        [[UIApplicationsharedApplication]setStatusBarHidden:NO];

    }];

    

    UIView *custom = [[UIViewalloc]initWithFrame:CGRectMake(0,0,0,0)];

    UIBarButtonItem *btn = [[UIBarButtonItemalloc]initWithCustomView:custom];

    [viewController.navigationItem setRightBarButtonItem:btn animated:NO];

    viewController.title = @" ";

    

    if ([GNDeviceversionPermit:7second:0]) { //下面这段话如果在IOS5上运行的话会显示有点问题,所以这个地方注释

        NSDictionary *attributes=[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor],UITextAttributeTextColor,[UIFontboldSystemFontOfSize:20],UITextAttributeFont,nil];

        [viewController.navigationController.navigationBarsetTitleTextAttributes:attributes];

    }

    

    [btn release];

    [custom release];

}



PS:1216日,后来又出现个问题,就是在其它页面把扫描到的内容保存到相册后,历史图片页面的右上角的“取消”键就又出现了,现在能想到的办法就是当保存到相册时去发个通知,当"历史图片"页面收到通知后,把UIImagePickerController的view移除掉,然后再添加

#pragma mark --

#pragma mark GNNotification

- (void)handleSaveImageTOCustomAlbum:(NSNotification*)notification

{

    if (_imagePickerController) {

        [_imagePickerController.view removeFromSuperview];

        [_imagePickerController removeFromParentViewController];

        [_imagePickerController release];

        _imagePickerController = nil;

        

//        [self initImagePickerControllerInterface];

        [self performSelector:@selector(initImagePickerControllerInterface) withObject:nil afterDelay:1];    //不知道为什么这个地方需要延时下在IOS6上才会有效果,不然还是会有"取消"键

     }

}



你可能感兴趣的:(关于将系统自带的UIImagePickerController 作为uitabbarcontroller时 present时出现问题的解决)