Application and UIViewController
Teasing ahead: why don't Bytes put up the PPT of the graphics-mirroring project...Copy the code
Application
- Application entry
- UIApplication is the symbol of the application
- Is a singleton
- You can do some application-level things with UIApplication
Application life cycle
- Active – activated
- Inactive – not activated
- Background – the Background
- Suspended – hung
- Not Running- Not Running
The UI configuration
- (Bool)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)LaunchOptions{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
Copy the code
Windows has a concept of level, high level Windows will be in the upper layer. [makeKeyAndVisible] makes a window a key window (main window) and visualizes it, blocking click events that are passed to the window.Copy the code
ViewController
- Managing view Hierarchy
- Typically, each ViewController manages one page
- Window is to show the clean face, VC is used to organize the interface, its most important property is view
- Each ViewController has a view property as the root view of the view it manages
- A view is a tree structure, and a view can have child views that have lifecycle callbacks when they are added to the view hierarchy
- Typically, each ViewController manages one page
- Handle view-related events
- ViewAppear (page display)
- ViewAppear (page destruction)
- Common viewControllers:
- UIViewController
- UINavigationController(container viewcontroller)
- UITabBarController(container viewcontroller)
Coordinate system and view hierarchy
- UIWindow
- The canvas of the user interface, the App may have more than one Window
- Normally it’s the root view in the view hierarchy, UIWindow inherits from UIView
- Responsible for distributing events to subviews
View life cycle
Frame, Bounds, and Center
UIView has three important layout properties: Frame, bounds, and Center
- The frame coordinate system relative to the SuperView usually starts at the top left corner
- The bounds coordinate system is relative to itself, usually starting at (0,0)
- Center is the location of its anchorPoint relative to superview
- AnchorPoint is generally the center of the view
Manual Frame-based Layout
Usually a frame describes the position and size of a view in its superView so when we say layout, we're always setting the origin and size of a view's frameCopy the code
advantages
- simple
- A high performance
disadvantages
- Poor maintainability
Automatic layout (AutoLayout)
- IOS device fragmentation, iOS6 introduced Autolayout
- RelativeLayout Dynamically calculates The size and Position of all the views in your view hierarchy, based on constraints pplaced on those views
RedView.Leading = 1.0 * BlueView.trailing + 8.0
Copy the code
I think it would be nice to have pictures here, but I'm sorry I'm not familiar with the graphic bed yet.Copy the code
The industry offers but lengthy apis, and the industry explores concise but syntactic DSLS
- Navigation /SnapKit (oc/SWIFT)
Making the address
Response chain and gesture
Response chain – UIEvent
- Click events detected on the screen are represented by UITouch objects, which are finally encapsulated into UIEvent as the message carrier of the event and passed on the response chain
- After a touch event occurs, the system adds the change time to an event queue managed by UIApplication
- UIApplication pulls the first event from the event queue and sends it down for processing, usually first to the main window of the application
- The main window (keyWindow) finds the most appropriate view in the view hierarchy to handle touch events
Response Chain — UIResponder Chain
- UIResponder
- -void)touchesBegan:(NSSet* )touches withEvent:(UIEvent* )event;
- -(void)tourchesMoved:(NSSet* )touches withEvent:(UIEvent* )event;
- -(void)tourchesEnded:(NSSet* )touches withEvent:(UIEvent* )event;
- -(void)tourchesCancelled:(NSSet* )touches withEvent:(UIEvent* )event;
- Refer to link brief book
Look for the View where the Event occurred: hit-testing
Hit-testing app: Expand the range of button clicksCopy the code
gestures
[Here’s an important diagram of the various UIXxxRecognizer classes]
- UIApplicationHandleEventQueue()
- UIEvent
- Gesture recognition
- Handle screen rotation
- Send to UIIWindow
- UIEvent
- Add gestures
- UIGestureRecognizerDelegate
- UIControl/UIButton inherits UIView, encapsulates event handling logic, and provides a convenient API for users to respond to events
Control has some common features
- UIView
- frame
- layer
- transform
- superview
- subviews
- UIControl
- enable
- selected
- highlighted
- target/action/enevt
- Others
- backgroundColor
- text
- backgroundimage
- font
Page composition
UI elements on the page
- Background – UIView
- Text-uilabel tags are often used to display fixed text, and their appearance is configurable. They can display normal strings, or attribute strings, allowing you to customize the appearance of label substrings.
- Image – UIImageView
- It can be used to display images in PNG or JPEG formats, as well as GIF sequences of images
- Gifs are not supported
- There are three different zooming strategies for images
- Button – UIButton UIButton inherits from UIControl
- Built-in combination of Lable and ImageView
- Title /icon configuration in different states
- Encapsulates a convenient API interface to handle user interaction events
Complex elements on the page
-
Scroll view – UIScrollView
UIScrollView is a control that displays content larger than the screen, can scroll vertically or horizontally, and supports zooming with gestures. It is the parent of many scrollable controls, including UITableView and UITextView
-
Slide list – UITableView
UITableView is implemented based on UIScrollView, which organizes pages by dividing rows and groups
- Use the UITableViewCell to represent 1 row in a list
- Reuse row-level view reuse based on UITableViewCekk
advantages
- High-performance, cell reuse, CPU/ memory friendly
- In line with the structured data expression of most apps
With these basic components, we can build complex pages to meet business needs
UITableView:DataSource & Delegate
- Create a TableView
- Specify DataSource and Delegate
- Implement DataSource and Delegate protocols:
- Specify the number of secetion groups and the number of rows for each group
- Specifies the height of row MTH in group NTH
- Specify cell type for row MTH in group NTH