Develop a tab bar program supporting the iPhone horizontal screen

Source: Internet
Author: User
When you develop a program for the iPhone, you may use the project template provided by xcode. One of these templates is called the tab bar application, which helps you quickly create a program based on the tab bar. However, the default template only supports the portrait screen.

When you develop a program for the iPhone, you may use the project template provided by xcode. One of these templates is called the tab bar application, which helps you quickly create a program based on the tab bar. However, the default template only supports portrait display. So how can we develop a program that supports both landscape and landscape screens? This article will discuss this issue.

 

 

Prepared by Matt long

Original address http://www.cimgf.com/2008/11/13/landscape-tab-bar-application-for-the-iphone/

 

 

Create a new tab bar program in xcode.

 

1. Press command + Shift + N, select the tab bar application in the iPhone OS, and click choose...

2. Write a name for the project, such as Tab test.

3. Click Save.

 

First, you will notice that the template generates two classes. One is firstviewcontroller, which is used to control the first view. The other name is tab_testappdelegate, which serves as the main controller of the program.

 

Take a look at the remaining code in firstviewcontroller. Most of the Code has been commented out, but you will notice that there is a way to support landscape screens. We are particularly concerned about shouldautorotatetointerfaceorientation. Remove the comment and return YES. This setting allows the Controller to support all directions.

  1. // Override to allow orientations other than the default portrait orientation.
  2. -(Bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation {
  3. // Return YES For supported orientations
  4. Return yes;
  5. }

 


 

In this way, when the iPhone is flipped, our view will also change. Compile and run the program using the simulator. When the simulator opens the program, select hardware-> rotate left in the menu. You will find that the view is not rotated when the device is rotated. Why?

 

All or none

 

Remember that the default tab bar program template creates a tab bar that supports two views. When we specifically told the firstviewcontroller object that supports horizontal screen, we did not tell the second view that it also supports horizontal review. The tab bar works in the same way if any View Controller limits the direction sensing.

 

This means that all controllers must call the-shouldautorotatetointerfaceorientation method the same way, and return YES to tell the system to enable landscape screen support. In our default tab bar program, we didn't specify the second view into the controller, because we didn't define the second controller. So where is the second controller? The answer is in interface builder. You can double-click mainwindow. XIB in xcode to open interface builder. Click the tab of the first view and select the identity tab in Inspector. Then you will find out what is going on.

 

 

Note that we use the uiviewcontroller class, which is the controller of our view. It provides the basic functions closely: this means that it does not fully provide all the functions of the controller. The default setting of screen rotation only supports portrait screen. In other words, only the derived class supports the-shouldautorotatetointerfaceorientation method to enable the horizontal screen.

 

If you want your program to support the horizontal screen, all your tab views must have their own view controller, then call-shouldautorotatetointerfaceorientation, and return YES to support the horizontal screen.

 

Conclusion

 

The iPhone is a very interesting platform that is very powerful, but it is slightly different from the Mac OSX system you are familiar. The trick is to remember the basic concepts of cocoa and MVC you have learned so that you can solve the problems you encounter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.