The iPhone Developer's Cookbook(4)


UIView and UIWindow
The iPhone rule goes like this: one window, many views.Metaphorically speaking, UIWindow is the TV set, and UIViews are the actors on your favorite show.

UIViews are user interface building blocks. Every iPhone user interface is built from UIViews displayed within one UIWindow, which is a specialized kind of UIView.

The UI at the beginning of certain classes (like UIView) stands for User Interface.

The iPhone offers two core classes that offer choices to users.
The UIAlertView class produces those blue pop-up windows you've seen in many applications.
The second choice-based class is UIActionSheet, which offers menus that scroll up from the bottom of the screen.As a rule, use action sheets when you have a number of options to choose from and alert views when you are presenting just two or three choices at most.
Both these presentations are modal.

Here's a quick rundown of the major classes provided by Cocoa Touch and what each control offers:
    UIButton: In Interface Builder, buttons are called Round Rect Buttons.
    UISegmentedControl
    UISwitch class provides a simple binary control in Cocoa Touch.
    UISlider class lets users choose a value from a specified range by sliding an indicator along a horizontal bar.
    Page controls let users move between pages, usually as part of a UIScrollView implementation. The UIPageControl class offers a series of small dots (like the ones you see on the iPhone's home page) showing the current page and letting users navigate to the next or previous pages.
    UITextFields are a kind of control that let you enter text.
    UITableView class provides the most commonly used table style. Tables offer rows of information (provided by the UITableViewCell class), which users scroll through and can select.
    UIPickerView class offers a kind of table, where users can select choices by scrolling individual wheels. A specialized version of this class is the UIDatePicker.

Of all the iPhone bars, only the UIToolbar class is meant for direct use.

UIActivityIndicatorView offers a spinning-style wheel, which is shown during an ongoing task.
When you want to communicate progress to a user, user the UIProgressView class.

View controllers aren't views. They are abstract classes with no visual representation; only views offer visual canvases. Instead, they help your views live in a larger application design environment. Do not set a frame the way you would with a normal UIView. UIViews use initWithFrame:; UIViewControllers user init.

UIViewController is the parent class for view controllers and the one you use to manage your primary views. The basic UIView Controller class manages each primary view's lifetime from start to finish and takes into account the changes that the view must react to along the way.

WIthout a view controller, your interface won't support automatic orientation updates. UIViewController instances are responsible for setting up how a view looks and what subviews it displays. Often they rely on loading that information from .xib files. A variety of instance methods such as loadView and viewDidLoad let you add behavior while or after a view sets up.

The UIViewController mediates between views and these external demands, allowing the view to change itself to meet these needs.

Any time you use a navigation-style project, you must assign it a root view controller. This is the view controller that lives at the top of the navigation tree. All other view controllers branch out from this one. The name of the .xib file and its class reflect this design necessity.

Whenever you use an image backdrop, always be sure to enable interactions. This little "gotcha" frequently snags developers who forget.

As you add more elements to your Interface Builder view, it becomes difficult to select the correct one by clicking on it. One handy tip is to Control +Shift+click on any view in an Interface Builder edit window to display a list of all views stacked at that point. You can choose an item from that list to select it.

The Control-drag shortcut creates connections.

One of the great things about Cocoa Touch is that you don't have to program entirely by hand or entirely using Interface Builder.

Whenever Xcode finds a .xib file whose name matches a class derived from UIViewController, it automatically loads that .xib when initializing an instance.

Cocoa Touch lets you recover objects from any .xib file by calling loadNibNamed: owner: options:. This returns an array of objects initialized from the .xib bundle, which you can then grab and use in your program.

The order of the items in the .xib file array mirrors the order of the items in Interface Builder's project window. Since this .xib contains exactly on top-level item, the code could just as easily use objectAtIndex:0 as lastObject.

UIViewController instances decide whether to respond to iPhone orientation by implementing the optional shouldAutorotateToInterfaceOrientation: method. This method returns either YES or NO, depending on whether you want to support autorotation to given orientation. To allow autorotation to all possible orientations, simply return YES.

Possible iPhone orientations passed to this method include
    UIDeviceOrientationUnknown
    UIDeviceOrientationPortrait
    UIDeviceOrientationPortraitUpsideDown
    UIDeviceOrientationLandscapeLeft
    UIDeviceOrientationLandscapeRight
    UIDeviceOrientationFaceUp
    UIDeviceOrientationFaceDown
Of these orientations, only the portrait and landscape varieties influence how a view autorotates.

转载于:https://www.cnblogs.com/leelike/archive/2011/11/21/Object-C-UIView-and-UIWindow.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值