Site icon Ravi Shankar

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.

 

Exit mobile version