[英]How to use UIImagePickerController with tabBar based application?
我正在制作一個基於tabBar和navigationBar的應用程序。 在它上面我點擊它時有一個按鈕然后在UIImagePickerControllerSourceTypePhotoLibrary的幫助下我打開了圖像庫但是imagePicker默認后退按鈕,取消按鈕未顯示在視圖上。 就像我使用UIImagePickerControllerSourceTypeCamera然后相機窗口打開但我無法看到單擊按鈕來捕獲圖像,因為它將被tabBar隱藏。 所以請幫我解決這個問題。 這是圖像的截圖。
您可以在TabbarController上顯示圖像選擇器(從AppDelegate獲取它或在其中實現它),而不是像這樣的視圖控制器:
YourAppDelegate* appDel = (YourAppDelegate*)[[UIApplication sharedApplication] delegate];
[appDel.tabBarController presentModalViewController:picker animated:YES];
注意:從ios 6 presentModalViewController:animated:不推薦使用並替換為presentViewController:animated:completion :
如果項目在故事板中,您將沒有對它的引用(您在代碼中創建的)。
相反,只需爬上視圖層次結構並以此方式獲取選項卡視圖控制器。
UITabBarController * tabBarController = (UITabBarController*)self.parentViewController;
[tabBarController presentViewController:picker animated:YES completion:^(void){
}];
然而,如果你在視線中出現,你將不得不處理在解雇后回來的相機。 (做一些狀態以防止或不在那里。)
我知道這是一個古老的問題,但我認為這將有助於人們度過一個美好的時光,因為這對我有用。
對我來說,這條線解決了這個問題,而選擇控制器來自Tab欄
picker.modalPresentationStyle = .custom;
您可以使用UITabBarControllerDelegate
的shouldSelectViewController
方法來完成以下操作:
(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
// Check if it's the "image picker" tab
if (viewController == self.imagePickerTabView) {
// Present image picker
return NO;
}
// All other cases switch to the tab
return YES;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.wantsFullScreenLayout = YES;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
showImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.wantsFullScreenLayout = YES;
picker.showsCameraControls = YES;
picker.navigationBarHidden = NO;
picker.toolbarHidden = NO;
picker.allowsEditing=NO;
[self presentModalViewController:picker animated:YES];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.