How to only enable portrait orientation for iPhone App

When developing an iPhone app in Xcode, if you have any requirement that only portrait orientation allowed then you can do the following.

Step 1: Open the implementation file for editing.

Step 2. Navigate to shouldAutorotateToInterfaceOrientation method. This methods is auto generated by Xcode while creating the project.

Step 3: replace the return statement with return (interfaceOrientation == UIInterfaceOrientationPortrait);. The update method should be displayed as shown below.

– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

This method will return true only when the orientation in Portrait mode.

Step 4: Now navigate to Project Folder on the navigattion bar. In the summary tab under Supported Device Orientations, make sure to un mark the other orientation except portrait.

In Category: Apple, Develop, iPhone

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 2 Comments

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.