IOS 在Ipad 橫屏 上使用UIImagePickerController

來源:互聯網
上載者:User

標籤:

轉載前請註明來源:http://www.cnblogs.com/niit-soft-518/p/4381328.html

最近在寫一個ipad的項目,該項目必須是橫屏。進入正題,有一項功能是要調用系統的牌照和相簿,於是本屌用了 UIImagePickerController,興沖沖的運行了一下,呵呵,崩掉了,然後帶著高逼格去查蘋果文檔,一堆英文,不懂,好吧,百度一下,發現好多同道中人說 UIImagePickerController必須要豎屏,不能橫屏~這讓我差點淚崩,又繼續看蘋果文檔,發現了新大陸:

 

  1. 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.