Everyone I am working on a tabbar-based app. I open camera on a screen in order to picture. But when camera is open, i cant see the Take photo button on the bottom. My guess is that the button gets hidden behind the tab bar. If I am right then I need to remove tab bar on the camera screen. Can anyone please tell me how I can remove the tab bar on the camera screen?
I am using this to display the camera:
[self presentModalViewController:imagePickerController animated:YES];
My app is tabbar-based and this code is written in a view controller which is associated with a tab bar item.
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 ani开发者_开发技巧mated:YES];
Present the image-picker controller from the tab-bar controller instead of the view controller it contains. In other words:
[self.tabBarController presentModalViewController:imagePickerController animated:YES];
try this:
[[[[UIApplication sharedApplication].delegate window] rootViewController] presentModalViewController:picker animated:YES];
/*
- (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
Set frame size to full for modal view so that it covers up the whole screen - Dimensions ~ (0,0,320,460)
imagePicker.view.frame = CGRectMake (0,0,320,460);
精彩评论