One, window and view
1. In iOS, use Windows and views to display the contents of the application on the screen. The window itself does not have any visible content, but it provides a basic container for the view of the application. The view defines a portion of the window that you want to populate with some content. For example, you might display images, text, shapes, or some combination of views. You can also use views to organize and manage other views.
Window
• What is a window?
• At least one window is required for each application, and typically the window is represented by an instance of the UIWindow class. Note that UIWindow inherits from UIView.
The Window object has the following responsibilities:
• It contains the visual content of the application • It provides a critical role for views and other application objects in touch events • Collaborate with view controllers to present data
Most iOS apps have only one uiwindow in their life cycle. And during the lifetime of the application, the window spans the entire device's home screen and the main nib file from the application is loaded (or created programmatically). However, if the application supports an external monitor that uses video output, it can create additional windows to display the content on that external monitor. All other windows are typically created by the system and are typically created when responding to specific events, such as incoming phone calls.
2. Create and configure UIWindow
Create a full-screen window self.window = [[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Self.window.backgroundColor = [Uicolor whitecolor]; The Viewcontroller as a window with the controller self.window.rootViewController = [[Uiviewcontroller alloc]init]; Show Window [Self.window makekeyandvisible];
3. Get current UIWindow and levels
• Get current Keywindow through uiapplication.
Keywindow is a message used to manage keyboards and non-touch classes, and only one window is Keywindow.
· UIWindow *keywindow = [uiapplication sharedapplication].keywindow; each UIWindow object configuration Windowlevel property, Most of the time should not change windowlevel.
· The UIWindow has 3 levels and corresponds to 3 display priorities. With the Windowlevel setting, the priority is: Uiwindowlevelalert>uiwindowlevelstatusbar>uiwindowlevelnormal
Two. UIScreen
The 1.UIScreen object can act as a replacement for the physical screen of the iOS device, [UIScreen mainscreen] bounds] get the device screen size, such as the size of the iphone and ipad, if you want to do more than
The UIScreen class should be used to get the dimensions. The latest IPHONE5 adaptation issues!
2. While iOS supports stacking a window over other windows, your application should never create multiple windows because it affects the delivery of events.
3. Several concepts of mobile screen
· Screen Size: The display size, which refers to the physical length of the screen, as indicated by the length of the screen diagonal.
· Resolution: screen resolution, which refers to the total physical pixels on the screen.
· Density: Density, indicating how many display points per inch. Density is based on resolution, that is, the pixel points scattered at fixed resolution, that is to say, the density of the screen is bigger.
· ASPECT RATIO: High ratio of screen width. Which is what we call the aspect ratio 4:3. Device-independent Pixe:dip, device independent pixels. Dip is a virtual pixel unit that specializes in
Used to define the UI for the program.
• Color scale: that is, usually we say 65536 colors, 260,000 colors, 16 million colors and no number looks different so big, this is actually just to represent the adjacent three levels only, of course, 16 million color display is the best.
Three. UIView
UIView represents a rectangular area on the screen that occupies an absolutely important place in the app because almost all visual controls in iOS are UIView subclasses.
Responsible for rendering the content of the area and responding to touch events that occur within that area
Features of the UIView:
1. Managing content in a rectangular area
2. Handling events in a rectangular area
3. Management of child views
4. Also can realize the animation UIView subclass also has these functions
is the inner level of the view
5. View structure and related functions
Cgpoint point = Cgpointmake (x, y); Position
Cgsize size = Cgsizemake (width,height); Size
CGRect rect = CGRectMake (x,y,width,height); Location and size
6. Create a View
View UIView *view1 = [[[UIView Alloc]initwithframe:cgrectmake] [[]]; View1.backgroundcolor = [Uicolor whitecolor]; View1.clipstobounds=yes; [Self.window Addsubview:view1];
7. Common Properties of view:
Alpha//Transparency
backgroundcolor//Background color Uicolor
subviews//Child View collection Nsarray
hidden//whether to hide bool
tag//Tag Value
Superview//Parent View UIView
Clipstobound//Remove part of bool that is out of view
multipletouchenabled//Whether to turn on multi-touch bool
userinteractionenabled//whether to respond to touch event bool
8. Coordinate system transformations are changed by transform properties
· Cgaffinetransformscale Scaling A View
· Cgaffinetransformrotate zoom rotation on the view
· Cgaffinetransformtranslate panning the view in its original position
· Cgaffinetransformidentity revert to the original state of the view
Amplification
-(ibaction) enlarge: (ID) Sender { Cgaffinetransform t = _colorview.transform; _colorview.transform = Cgaffinetransformscale (t, 1.2,1.2);} Narrowing-(ibaction) Narrow: (ID) Sender { Cgaffinetransform t = _colorview.transform; _colorview.transform = Cgaffinetransformscale (t,0.7,0.7);} Rotation-(ibaction) rotate: (id) Sender { Cgaffinetransform t = _colorview.transform; _colorview.transform = Cgaffinetransformrotate (T,M_PI/18);}
Restore-(ibaction) Reduction: (UIButton *) Sender { //cgaffinetransform t = _colorview.transform; _colorview.transform = cgaffinetransformidentity; } Pan-(Ibaction) Translation: (UIButton *) Sender { Cgaffinetransform t = _colorview.transform; _colorview.transform = Cgaffinetransformtranslate (T, 20, 20);}
9. View Animations
There are several properties in the UIView object that support animation:
- Frame- You can use this to animate the size and position of the view
- Bounds -Use this to animate the size of the view
- Center -Use this to animate the position of the view
- Transform -Use this to flip or zoom in on a view
- Alpha -Use this to change the transparency of the view
- BackgroundColor -Use this to change the background color of the view
- Contentstetch- Use this to change how the view content is stretched
Steps:
1) Start and design the animation
[UIView Beginanimations:nil Context:nil]; How many seconds each animation lasts [UIView setanimationbeginsfromcurrentstate:10]; Set number of repetitions [UIView setanimationrepeatcount:1];
2) What to do with animation
Cgaffinetransform t = self.tuview.transform; Self.tuview.transform = Cgaffinetransformscale (t,100, n); Self.tuview.center = Self.view.center; Self.tuview.transform = Cgaffinetransformrotate (T,M_PI/4); Self.tuview.alpha = 0.1;
3) Submission Screen
[UIView commitanimations];
UIView and UIWindow's explanation