3.3 application practices and explanations
In this section, we will actually write this application and explain it. Write and explain the application skeleton, view flip animation, main view UI and code, Master View Controller code, Back View UI and code, and Back View Controller in this order.
3.3.1 construct an application skeleton
This book uses Xcode3.2 to provide a template for compiling practical applications. Figure 3-11 is the template of Xcode3.2. The Utility Application option is used to create practical applications.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S12450U-0.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-11 Practical Application Template
Unfortunately, the original author code of this application is not using the Xcode3.2 template. Let's compare their differences, as shown in the class diagram 3-12 generated by Xcode3.2.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1246219-1.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-12 classes generated by Xcode3.2
In order to respect the original author, if this book involves problems caused by historical versions, we will continue to introduce and build applications based on the original application version.
Comparing Class Diagrams 3-8 and 3-12, we will find that Xcode3.2 does not have two custom view classes: MainView and FlipsideView, but directly uses the UIView class. In Xcode3.2, The MainViewController class also implements a FlipsideViewControllerDelegate protocol, the FlipsideViewControllerDelegate protocol is not available in earlier versions, while Xcode3.2 does not have the RootViewController class. This is the key to the difference between the two versions. In the old version, view redirection and return are controlled through the root controller RootViewController. In Xcode3.2, FlipsideViewControllerDelegate is implemented through MainViewController, mainViewController is the root controller even if the master view controller is used.
Because we want to build the same class as the old version, we need to add MainView, FlipsideView, and RootViewController classes. Create MainView and select the Main View folder. Right-click the New File dialog box and choose Objective-C class from the shortcut menu. Set Subclass to UIView and click Next, enter MainView in the class name.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1244F0-2.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-13 create a UIVew
After MainView is generated, you also need to modify the corresponding nib file. Double-click MainView. xib in Xcode, and then Interface Builder will open the MainView. xib window, as shown in Figure 3-14,
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S124G50-3.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-14 MainView. xib window
From Figure 3-14, we can see that the View type is UIView. We need to change it to MainView. To achieve this purpose, select menu Tools> Inspector to open the checker window, select the tag to open the checker 3-15, and select the MainView class.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S12423Z-4.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-15 view checker
Double-click Main View to open the design window 3-16. This View is generated using Xcode3.2. We need to restore it to the default View status, as shown in Figure 3-17.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1243917-5.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-16 create a view using the Xcode3.2 template Figure 3-17 view after modification
To achieve this, you need to delete the button and change the view background color to the default color. The delete button can be deleted by clicking the button with the mouse. to modify the view background, you need to open the checker window and select the tag 3-18, modify the Background property to make the Background color white by default.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S124F23-6.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-18 modify the view background
Follow the above method to create the FlipsideView class. After this class is created, you need to modify its corresponding FlipsideView. xib file. FlipsideView is opened in Interface Builder. in the xib window, double-click Flipside View to open the design window, as shown in Figure 3-19. This View is generated using Xcode3.2. We need to restore it to the default View status, as shown in Figure 3-20.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1241452-7.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-19 create a view using the Xcode3.2 template Figure 3-20 view after modification
To achieve the effect of Figure 3-20, you need to delete the Title navigation bar. In this application, the navigation bar is dynamically added to the view through code, rather than being dragged in the View Design window. After deleting the navigation bar and repairing the background, we will find that the view has a status bar as shown in 3-21.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1243233-8.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-21 Status Bar View
We need to remove this Status Bar, open the view checker 3-22, and select the Status Bar as Unspecified.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1242213-9.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-22 view checker
And configure their creation process exactly the same. I will not introduce them too much here. The following describes how to create and configure RootViewController. Select a folder, right-click the New File dialog box, and choose UIViewController subclass from the shortcut menu. In the Options section, remove the With XIB for user interface, that is, do not create a nib file. Click Next and enter RootViewController in the class name.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S124J04-10.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-23 create a View Controller
After the RootViewController is generated, you also need to modify the MainWindow. xib file. Double-click MainWindow. xib in Xcode, and then Interface Builder will open the MainWindow. xib window 3-24. Click MainViewController and choose Tools> Inspector to open the checker window. Select the tag to open the checker window and select the RootViewController Class in the Class.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/0S1241Q3-11.jpg "title =" Click "Here To EnLarge" border = "0"/>
Figure 3-24 MainWindow. xib window
This article from the "Guan Dongsheng" blog, please be sure to keep this source http://2009315319.blog.51cto.com/701759/880172