1:uiwindow Knowledge Point
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { Self.window=[[UIWindow Alloc]initwithframe:[[uiscreen Mainscreen]bounds]]; Self.window.backgroundColor=[Uicolor redcolor]; Self.window.rootViewController=[[Viewcontroller alloc]init]; [Self.window makekeyandvisible]; return YES;}
IOS9 require all UIWindow have rootviewcontroller, if not Rootviewcontroller will error;
(a) "Self.window makekeyandvisible" makes the window the main window and displays it. This is the way to display the information on the screen.
(b) Because window has makekeyandvisible this method, can let this window show out of thin air, and the other view does not have this method, so it can only rely on the Window,window display, The view is attached to the window to show it.
(c) "Self.window make Keywindow"//Let UIWindow be the main window, but not displayed.
(d) [UIApplication Sharedapplication].windows opens a list of UIWindow in this app so you can touch any UIView object in the app (the keyboard that pops up in the text, In a new UIWindow)
(d) [UIApplication Sharedapplication].keywindow (Gets the application's main window) is used to receive UIWindow for keyboard and non-touch class message events, And only one uiwindow at a time in the program is Keywindow.
Tip: If a text box inside a UIWindow cannot enter text, it may be because this uiwindow is not Keywindow
(f) View.window obtain the UIWindow of a UIView
2:uinavigationcontroller Knowledge points
A. Four ways to add the controller to the navigation controller
The first type:
1. Create a navigation controller
Uinavigationcontroller *nav=[[uinavigationcontrolleralloc]init];
2. Set the navigation controller as the root view of window
Self.window.rootviewcontroller=nav;
3. Add
Yyoneviewcontroller *one = [[Yyoneviewcontroller alloc] init];
[Nav Pushviewcontroller:one Animated:yes];
The second type:
1. Create a navigation controller
Uinavigationcontroller *nav=[[uinavigationcontrolleralloc]init];
2. Set the navigation controller as the root view of window
Self.window.rootviewcontroller=nav;
3. Add
Yyoneviewcontroller *one = [[Yyoneviewcontroller alloc] init];
[Nav Addchildviewcontroller:one];
The third type:
1. Create a navigation controller
Uinavigationcontroller *nav=[[uinavigationcontrolleralloc]init];
2. Set the navigation controller as the root view of window
Self.window.rootviewcontroller=nav;
3. Add
Yyoneviewcontroller *one = [[Yyoneviewcontroller alloc] init];
[Email protected] [one]; (added to the stack of the navigation controller)
Description: nav.viewcontrollers;== nav.childviewcontrollers; Note that the property is read-only and therefore cannot be written as follows. Nav.childviewcontrollers = @[one];
The fourth type: the most common method
Yyoneviewcontroller *one=[[yyoneviewcontroller Alloc]init];
Uinavigationcontroller *nav=[[uinavigationcontroller Alloc]initwithrootviewcontroller:one];
B. The title of the current sub-controller interface navigation bar and the settings that correspond to the returned caption
[Email protected] "first interface";
self.navigationitem.backbarbuttonitem=[[uibarbuttonitemalloc]initwithtitle:@ "return one" style: Uibarbuttonitemstyleplain Target:nilaction:nil];
C. Add a button to the navigation bar
Description: You can add one, or you can add multiple (arrays)
Add a button to the left of the navigation bar (a button that adds a camera icon) that will cover the back
Self.navigationitem.leftbarbuttonitem=[[uibarbuttonitem Alloc]initwithbarbuttonsystemitem: Uibarbuttonsystemitemcamera Target:nil Action:nil];
D. Interface jump
Jumps to the second interface (currently the third one, removing the controller at the top of the current stack)
[Self.navigationcontroller Popviewcontrolleranimated:yes];
Remove all controllers except the stack base controller
[Self.navigationcontroller Poptorootviewcontrolleranimated:yes];
Whenever a controller in the stack is passed in, it jumps to the specified controller [self.navigationcontroller poptoviewcontroller:<# (Uiviewcontroller *) #> animated: <# (BOOL) #>];
Description
The navigation controller manages the sub-controller in the form of a stack (advanced back-out), The view displayed on the navigation controller is always the view of the top controller, a navigation controller has only one navigation bar, which means that all self-controllers have a single navigation bar.
Attached: Prints all child controls underneath the current window and saves them through an XML file
//Application gets focus (represents the ability to interact with the user)- (void) Applicationdidbecomeactive: (UIApplication *) application{NSLog (@"applicationdidbecomeactive"); Uinavigationcontroller*nav = (Uinavigationcontroller *) Self.window.rootViewController; Uinavigationbar*bar =Nav.navigationbar;//NSLog (@ "%@", Nsstringfromcgrect (Bar.frame));NSString*str =[self DigView:self.window]; [Str writetofile:@"/users/apple/desktop/ios6.xml"Atomically:yes]; }/** * returns all hierarchies of incoming VEIW * * @param view needs to get a hierarchical view * * @return string*/-(NSString *) Digview: (UIView *) view{if([View Iskindofclass:[uitableviewcellclass]])return @""; //1. Initializensmutablestring *xml = [nsmutablestringstring]; //2. Label Start[XML AppendFormat:@"<%@ frame=\"%@\"", view.class, Nsstringfromcgrect (View.frame)]; if(!Cgpointequaltopoint (View.bounds.origin, Cgpointzero)) {[XML AppendFormat:@"bounds=\"%@\"", Nsstringfromcgrect (view.bounds)]; } if([View Iskindofclass:[uiscrollviewclass]]) {Uiscrollview*scroll = (Uiscrollview *) view; if(!uiedgeinsetsequaltoedgeinsets (Uiedgeinsetszero, Scroll.contentinset)) {[XML AppendFormat:@"contentinset=\"%@\"", Nsstringfromuiedgeinsets (Scroll.contentinset)]; } } //3. Decide if you want to end if(View.subviews.count = =0) {[XML appendString:@"/>"]; returnXML; } Else{[XML appendString:@">"]; } //4. Traverse all the child controls for(UIView *childinchview.subviews) {nsstring*childxml =[self digview:child]; [XML Appendstring:childxml]; } //5. End of label[XML AppendFormat:@"</%@>", view.class]; returnxml;}
3:uicollectionviewlayout Custom Knowledge points
A: First look at its open properties and methods, you can use the property corresponding to its method, the method is more flexible
@protocol Uicollectionviewdelegateflowlayout <UICollectionViewDelegate>@optional-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Sizeforitematindexpath: (Nsindexpath *) Indexpath;-(Uiedgeinsets) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Insetforsectionatindex: (nsinteger) section;-(CGFloat) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Minimumlinespacingforsectionatindex: (nsinteger) section;-(CGFloat) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Minimuminteritemspacingforsectionatindex: (nsinteger) section;-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout referencesizeforheaderinsection: (nsinteger) section;-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout referencesizeforfooterinsection: (nsinteger) section; @endNS_CLASS_AVAILABLE_IOS (6_0) @ Interface Uicollectionviewflowlayout:uicollectionviewlayout@property (nonatomic) cgfloat minimumlinespacing;@ Property (nonatomic) CGFloat minimuminteritemspacing; @property (nonatomic) cgsize itemsize; @property (nonatomic) Cgsize estimateditemsize Ns_available_ios (8_0); //defaults to cgsizezero-setting a Non-zero size enables cells that self-size Via-preferredlayoutattributesfittingat Tributes:@property (nonatomic) uicollectionviewscrolldirection scrolldirection;//default is Uicollectionviewscrolldirectionvertical@property (nonatomic) cgsize headerreferencesize; @property (nonatomic) cgsize footerreferencesize; @property ( nonatomic) uiedgeinsets Sectioninset;//Set These properties to YES to get headers this pin to the top of the screen and footers that pin to the bottom while Scrolling (similar to UITableView).@property (nonatomic) bool Sectionheaderspintovisiblebounds Ns_available_ios (9_0); @property (nonatomic) bool Sectionfooterspintovisiblebounds Ns_available_ios (9_0); @end
B:item size (size of each item), which can be flexibly defined to each item
Layout.itemsize = Cgsizemake (30,20);
Or
-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Sizeforitematindexpath: (Nsindexpath *) Indexpath;
C:line spacing (spacing per line)
@property (cgfloat) minimumlinespacing
Or
-(CGFloat) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Minimumlinespacingforsectionatindex: (nsinteger) Section;
Note: This side is set to its small space per line, the actual if greater than this spacing to the self-whichever;
D:inter cell spacing (spacing per line of internal cell item)
@property (cgfloat) Minimum interitemspacing
Or
-(CGFloat) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Minimuminteritemspacingforsectionatindex: (nsinteger) Section;
Note: The same is set to the minimum spacing, the actual if larger than the first
E:scrolling direction (scrolling direction)
You can set the Scrolldirection property. Two values are as follows
Uicollectionviewscrolldirectionvertical
Uicollectionviewscrolldirectionhorizontal
F:header and Footer Size (header and footer sizes)
Here are some explanations for the header and footer.
N also supplementary views
n provides the content by means of a data source, as follows
-CollectionView:viewForSupplementaryElementOfKind:atIndexPath:
N Two constants (types)
Uicollectionelementkindsectionheader
Uicollectionelementkindsectionfooter
n also need to register a class and remove the view from the queue
-RegisterClass:forSupplementaryViewOfKind:withReuseIdentifier:
-RegisterNib:forSupplementaryViewOfKind:withReuseIdentifier:
-DequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:
The size of the header and footer is configured as follows:
1) can be configured globally with the following properties
@property (cgsize) headerreferencesize
@property (cgsize) footerreferencesize
2) You can also configure each section via delegate, as shown in the following code
-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Referencesizeforheaderinsection: (nsinteger) Section;
-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) collectionviewlayout Referencesizeforfooterinsection: (nsinteger) Section;
When vertical, you need to set the height, when the level, you need to set the width
G:section Inset (Section Inset is the boundary range of the cell in a
@property uiedgeinsets Sectioninset;
Or
-(Uiedgeinsets) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout*) Collectionviewlayout Insetforsectionatindex: (nsinteger) Section;
When used:
Uicollectionviewflowlayout *layout = [[Uicollectionviewflowlayout alloc] init]; = [[Uicustomcollectionview alloc] Initwithframe:cgrectmake (ten, main_screen_width-2* the Collectionviewlayout:layout];
iOS Development Basics-Fragmentation 39