IPhone ProgrammingAdd a delivery Sub-AccountViewInstance learning is the content to be introduced in this article, mainly for systematic learning.Iphone ProgrammingSome details andViewFor more information, see this article.IPhone ProgrammingThe center adopts two important models:
Object-Oriented model
Model-View-controller (MVC) Design Mode
MVC division on iPhone:
View
Provided by the UIView class and its subclass and Its Related UIViewController class. PS: For Controller, a container is used to store instances of the UIView class and layout items on the screen.
Controller
Achieve through 3 key technologies: Delegation, target operations and notifications
Model
The model method provides data by dragging the data source, meaning, and other protocols. The callback method triggered by the controller must be implemented.
Instance learning
In the example of P47 in the Pdf version, learn from the official website of Apple:
UIView class
Common attributes:
- Superview
- Subviews
- Window
- AutoresizingMask UIViewAutoresizing constant,
- Commonly used UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleRightMargin
- AutoresizesSubviews: indicates whether the subview automatically resets the size.
- Tag: tag of the View
Common Methods:
- AddSubview
- InsertSubview
- RemoveFromSuperview
- ViewWithTag
UIViewController class
Provides a basic view-management model for Apple applications.
UINavigationController and UITabBarController are subclasses of this class. They provide additional behavior operations to manage controllers and views of complex hierarchies.
Common attributes:
View:
The view managed by the current controller. It is the view currently visible to the Controller.
Common Methods:
LoadView:
Create a view for the controller.
WillRotateToInterfaceOrientation:
Used to notify the controller of screen flip to respond to corresponding changes
ShouldAutorotateToInterfaceOrientation:
Returns a Bool value to indicate whether the current view Controller supports the specified direction.
This function involves a constant, as follows:
UIInterfaceOrientation constant:
- typedef enum {
- UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
- UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
- UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
- UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
- } UIInterfaceOrientation;
Used to determine whether the screen horizontal and vertical la s are supported. For example, videos are generally horizontally watched. Therefore, the value can only be UIDeviceOrientationLandscapeRight UIDeviceOrientationLandscapeLeft. The complete code is as follows:
- // Allow the view to respond to 2 iPhone Orientation changes,like:
- -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation == UIDeviceOrientationLandscapeRight || interfaceOrientation == UIDeviceOrientationLandscapeLeft);
- }
Geometric structure:
CGRect
- A structure that contains the location and dimensions of a rectangle.
-
- struct CGRect {
- CGPoint origin;
- CGSize size;
- };
- typedef struct CGRect CGRect;
CGPoint
- A structure that contains a point in a two-dimensional coordinate system.
-
- struct CGPoint {
- CGFloat x;
- CGFloat y;
- };
- typedef struct CGPoint CGPoint;
CGSize
- A structure that contains width and height values.
-
- struct CGSize {
- CGFloat width;
- CGFloat height;
- };
- typedef struct CGSize CGSize;
CGFloat
- The basic type for all floating-point values.
- typedef float CGFloat;// 32-bit
- typedef double CGFloat;// 64-bit
Summary:IPhone ProgrammingAdd a delivery Sub-AccountViewI hope this article will help you with the introduction of instance learning!