【问题标题】:Hide tabbar when camera is open打开相机时隐藏标签栏
【发布时间】:2011-07-22 20:06:26
【问题描述】:

我正在开发基于标签栏的应用程序的每个人。我在屏幕上打开相机以便拍照。但是当相机打开时,我看不到底部的拍照按钮。我的猜测是按钮隐藏在标签栏后面。如果我是对的,那么我需要删除相机屏幕上的标签栏。谁能告诉我如何删除相机屏幕上的标签栏?

我正在使用它来显示相机:

[self presentModalViewController:imagePickerController animated:YES];

我的应用是基于标签栏的,此代码是在与标签栏项目关联的视图控制器中编写的。

if (!imagePickerController) {
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;

// If our device has a camera, we want to take a picture, otherwise, we just pick from
// photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
}else
{
    [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Your device does not support taking photos from camera. Redirecting you to Photos Library instead." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

// image picker needs a delegate so we can respond to its messages
imagePickerController.delegate = self;
}
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];

【问题讨论】:

  • 那里应该没有标签栏。这是一个模态视图控制器,应该有一个拍照按钮……嗯。
  • 嗨莱戈拉斯感谢您的回复。我有 iPhone 4G。当我在其上运行应用程序时,我看到底部的标签栏并且相机保持打开状态。在相机视图的顶部,我可以看到闪光灯和切换相机按钮。标签栏在那里,我不希望它出现在相机屏幕上。请帮忙!
  • 根据我的经验,该选项卡无法显示。请发布您的完整代码。
  • Legolas,我发布了我的代码作为答案。

标签: iphone objective-c camera uitabbarcontroller


【解决方案1】:

从标签栏控制器而不是它包含的视图控制器中显示图像选择器控制器。换句话说:

[self.tabBarController presentModalViewController:imagePickerController animated:YES];

【讨论】:

  • 我试过但没有任何反应。图像选择器控制器不显示。
  • 嗯。您的视图控制器是否在导航控制器内?您可能必须改用self.navigationController.tabBarController
【解决方案2】:

试试这个:

[[[[UIApplication sharedApplication].delegate window] rootViewController] presentModalViewController:picker animated:YES];

【讨论】:

    【解决方案3】:
    /*
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization.
        }
        return self;
    }
    */
    
    
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
        imagePickerController.delegate = self;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please choose the category you want your picture to be uploaded in." delegate:self cancelButtonTitle:@"General" otherButtonTitles:@"Fresh Cuts", nil];
        [alert show];
    }
    
    
    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations.
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    */
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Release any cached data, images, etc. that aren't in use.
    }
    
    - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
        // the user clicked one of the OK/Cancel buttons
        if (buttonIndex == 0)   //general
        {
            selected_category = 0;
        }
        else                    // fresh cuts
        {
            selected_category = 1;
        }
    }
    
    
    -(IBAction) uploadFromCameraButtonPressed{
        if (!imagePickerController) {
            imagePickerController = [[UIImagePickerController alloc] init];
            imagePickerController.delegate = self;
    
            // If our device has a camera, we want to take a picture, otherwise, we just pick from
            // photo library
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
            {
                [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
            }else
            {
                [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"Your device does not support taking photos from camera. Redirecting you to Photos Library instead." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
    
            // image picker needs a delegate so we can respond to its messages
            imagePickerController.delegate = self;
        }
    
        [self presentModalViewController:imagePickerController animated:NO];
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSData *imageData = UIImagePNGRepresentation(image);
        NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_email"];
    
        NSMutableString *imageName = [[[NSMutableString alloc] initWithCapacity:0] autorelease];
    
        CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
        if (theUUID) {
            [imageName appendString:NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID))];
            CFRelease(theUUID);
        }
        [imageName appendString:@".png"];
    
        StatusBO *statusObj = [PhotoBO uploadImageFile:userName imageData:imageData file_name:imageName c_id:self.selected_category];
    
        if(statusObj.errorOccured == YES){
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:statusObj.errorTitle message:statusObj.errorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }else{
        //  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:statusObj.errorTitle message:statusObj.errorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            //[alertView show];
            [self dismissModalViewControllerAnimated:NO];
        }
    }
    
    
    -(IBAction) uploadFromFileButtonPressed{
        imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentModalViewController:imagePickerController animated:YES];
    }
    
    
    - (void)viewDidUnload {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    -(IBAction) backButtonPressed{
        [self.view removeFromSuperview];
    }
    
    -(IBAction) takePhotoFromCamra{
    
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    
    @end
    

    【讨论】:

      【解决方案4】:

      将模态视图的帧大小设置为完整,以便覆盖整个屏幕 - 尺寸 ~ (0,0,320,460)

      imagePicker.view.frame = CGRectMake (0,0,320,460);
      

      【讨论】:

      • 我猜它与标签栏控制器有关。实际上我有一个视图控制器,当我选择一个标签栏项目时它会打开。现在在这个视图控制器的视图上,我添加另一个视图控制器的视图作为子视图。我发送给您的代码来自第二个视图控制器。这可能是问题吗?
      • 不,这仍然不是问题。模态视图控制器的全部意义在于它应该对用户完全可见。它位于所有视图之上。
      • 我通过编写 [appDelegate.tabBarController presentModalViewController:imagePickerController animated:YES]; 来修复它其中 appDelegate 是我的 Delegate 类的实例。我对么?顺便说一句,代码的工作原理。
      • 哈哈。是的。为什么不。那肯定可以解决问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      相关资源
      最近更新 更多