標籤:
轉載前請註明來源:http://www.cnblogs.com/niit-soft-518/p/4381328.html
最近在寫一個ipad的項目,該項目必須是橫屏。進入正題,有一項功能是要調用系統的牌照和相簿,於是本屌用了 UIImagePickerController,興沖沖的運行了一下,呵呵,崩掉了,然後帶著高逼格去查蘋果文檔,一堆英文,不懂,好吧,百度一下,發現好多同道中人說 UIImagePickerController必須要豎屏,不能橫屏~這讓我差點淚崩,又繼續看蘋果文檔,發現了新大陸:
Present the user interface. On iPhone or iPod touch, do this modally (full-screen) by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller.
On iPad, the correct way to present an image picker depends on its source type, as summarized in this table:
Camera |
Photo Library |
Saved Photos Album |
Use full screen |
Must use a popover |
Must use a popover |
The table indicates that on iPad, if you specify a source type of UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeSavedPhotosAlbum, you must present the image picker using a popover controller, as described in Presenting and Dismissing the Popover. If you attempt to present an image picker modally (full-screen) for choosing among saved pictures and movies, the system raises an exception.
On iPad, if you specify a source type of UIImagePickerControllerSourceTypeCamera, you can present the image picker modally (full-screen) or by using a popover. However, Apple recommends that you present the camera interface only full-screen.
好吧,以我四級未過的英語水平就不做翻譯了,大概的意思就是說 如果在ipad中用uiimagepickercontroller,必須使用POPOverController,然後我就試著寫了一下,果然很OK!
以下是代碼:
一個調用相簿的功能:
/* 相簿 */-(void)Photo:(UIButton *)sender{ imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // 編輯模式 imagePicker.allowsEditing=NO; UIPopoverController *pop=[[UIPopoverController alloc]initWithContentViewController:imagePicker];// [self presentViewController:imagePicker animated:YES completion:NULL]; [pop presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];}
效果:
IOS 在Ipad 橫屏 上使用UIImagePickerController