Thursday, March 4, 2010

How To Use UIImagePickerController In Landscape App




My app just got rejected for displaying UIImagePickerController in the landscape mode. As Apple doc stated, UIImagePickerController (will be refered as UIIPC from now on) only works in portrait mode. For SDK 3.0+, this is no problem since i think it will auto display in portrait mode (correct me if im wrong). But for me, who is using 2.2.1 still, becomes a problem. I know there are quite a few posts about this issue with solutions but I tried all those and proves to be either "not working" or "too difficult to implement.". Especially those that suggest to apply transform to all the views object.



The problem is that the UIIPC launched in landscape mode causes the thumbnails to be stretched in devices, and appears funny in simulator. Such as below:


After few hours of banging my head on my MacBook, I came up with a simple hack that I think works ok. Here's one way how to solve this problem - very easy way without needing to apply transform to all of your objects and views. This is a sample app i created. From launch, the app starts from landscape.  

Now when I press a button to load a photo (calling UIIPC - either savedphotosalbum/photolib), the app display a "transition view" that halts the operation until the user rotates the device. Put a message/text on it to ask the user to rotate the device to proceed. At the time of this view displaying, also set a GLOBAL BOOL FLAG, (named WANTSPORTRAIT for me), to YES. (initially set to NO)

Then, when the user rotates it, detect the orientation (by the delegate function of  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation). In this delegate function, detect the flag and if it is set, call the UIIPC and return UIInterfaceOrientationPortrait. Voila, now your UIIPC is in Portrait.

The next thing to do is to handle the selected image/photo. Once the image/photo is selected, the appropriate delegate function will be called (for 4.0, it is - - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info. In this function set WANTSPORTRAIT to NO and again, display the transition view with a message asking the user to rotate to landscape. (You can customize these messages, and even easily apply simple transform on them to make it appear nice). 

And when the user rotates it again back to landscape, the delegate detects it and return the orientation back to landscape. The project sample probably is not perfect (eg if user rotates the other way or etc, you need to modify it to handle all of orientation)

This method is accepted by Apple Reviewer. 2 of my apps are using this method and appears to be accepted by users.

19 comments:

  1. what if you just want to use the camera to take photos in landscape mode?

    ReplyDelete
  2. How 2 create a custom slider programatically...........

    ReplyDelete
  3. I done Twitter application for iphone..everithing going good bt TweetMessage is not posted....Plz....help me

    ReplyDelete
  4. This issue is not a problem anymore since IOS4 everything is peachy - the UIImagePickerController will automatically shown in portrait mode nicely even when your app is landscape.

    ReplyDelete
  5. Nice Post!! LiveWebTutors is the preferred service for offering essay writing service . The service solutions are blessed with a team of diligent writers, researchers and editors to provide you with the right assistance within the perfect timeline.

    ReplyDelete
  6. Thank you for sharing this informative article. I'll keep an eye on your blog for new posts. I found this profile about spacebar test very useful. You will be able to see your results immediately after completing the test.

    ReplyDelete
  7. Very nice blog, a debt of gratitude is in order for sharing such delightful data with us. Thank you. Check ku post utme past questions and answers

    ReplyDelete
  8. I enjoyed reading your article very much. It was one of the most interesting posts I've read so far. Can't wait to read more of your posts. I am sharing a genuine profile for you to read where you can find out about words per minute tests. Refer to the profile for more information.

    ReplyDelete
  9. First of all, your blog is fun. I would love to see more articles like this. I will always check your blog next time, as you have great articles. If you would like to learn more about Mouse Test Online Tool, you can also visit the article I wrote about the topic. This post requires a lot of research and time for me. Please visit online mouse test and let us know what you think.

    ReplyDelete
  10. You have a lot of interesting content on your blog. No doubt I'm having a good time here, and it looks like others are too! Good job, keep it up. If u want more information about CPS. CPS helps you to calculate your number of clicks per second. please refer to the article. Thank you so much for taking the time to read this.

    ReplyDelete
  11. Very fantastic piece of content I see here on your blog, you have put out very vital tips and information for your readers. Thanks for sharing. ksu approved school fee schedule

    ReplyDelete
  12. Nice. This initial effort looks very intresting, Keep this spirit up. Now it's time to avail Hi Vis Bomber jacket for more information.

    ReplyDelete
  13. I am happy to see your article. This blog is about UI image pickers. They also provide us a knowledge of this controller and how to be used it. Now it's time to avail shutters in birmingham for more information.

    ReplyDelete
  14. Thanks dude! I was having this problem since 3 hours. Now I can easily do my work. Keep sharing informative blogs like this. It's time to get Outbound Call Center Services click for more information.

    ReplyDelete
  15. This is a good blog related to the use of UIImage Picker Controller. It is such an informative blog for me. Thanks for sharing this blog. Keep sharing more blogs. Now it's time to avail Luxury Limo Services in Long Beach CA for more information.

    ReplyDelete
  16. An amazing article related to the UI image picker controller. All the features and the functions explain very well. Thank you for sharing with us. Now its time to avail Limo service West Palm Beach for more information.

    ReplyDelete
  17. It is an interesting article related to the use of UI image picker controller in landscape App. This is just like the creativity of an object. Thankyou for share with us. Now its time to avail Car Services in Orlando for more information.

    ReplyDelete
  18. Appreciate the clear and concise information. Don't overlook this article CPS Test. Have you tried CPS clicking? It's a technique that can significantly up your CPS.

    ReplyDelete