我正在使用基于tabbar的应用上的每个人。我在屏幕上打开相机以便拍照。但是当相机打开时,我看不到底部的拍照按钮。我的猜测是按钮隐藏在标签栏后面。如果我是对的,那么我需要删除相机屏幕上的标签栏。谁能告诉我如何删除相机屏幕上的标签栏?
我用它来显示相机:
[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];
答案 0 :(得分:4)
从标签栏控制器而不是它包含的视图控制器呈现图像选择器控制器。换句话说:
[self.tabBarController presentModalViewController:imagePickerController animated:YES];
答案 1 :(得分:2)
试试这个:
[[[[UIApplication sharedApplication].delegate window] rootViewController] presentModalViewController:picker animated:YES];
答案 2 :(得分:0)
/*
- (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
答案 3 :(得分:0)
为模态视图将帧大小设置为完整,以便它覆盖整个屏幕 - 尺寸〜(0,0,320,460)
imagePicker.view.frame = CGRectMake (0,0,320,460);