I. Interface Building 1. Project Requirements main interface can scroll left and right, also can scroll up and down, click the button jump interface 2. Analysis Interface Click the button jump interface to customize the Uitabbarcotroller to achieve left and right scrolling, you can use ScrollView to implement or uicollectionview Up and down scrolling, with TableView can achieve 3. Select Implementation scenario one: Uitabbarcotroller + scrollview + TableView + Titleview (Tabbar) uiscrollview drawbacks: No off-screen rendering optimization use of ScrollView, TableView that are not shown will render, render less memory, create many objects off-screen rendering: If an interface is not displayed on the screen, it will not render, and if it is on the screen, it will render scenario two: Uitabbarcotroller + uicollectionview + tableView + scrollview (tabbar bar) can expand title Uicollectionview benefits: Optimize off-screen rendering, not less create uitableview tableview add Uicollectionview cell inside 4. Interface building Implementation steps 4.1 first create a uiviewcontriller 4.2 Create Uicollectionview Add to Uiviewcontriller view above Create Uicollectionview, set layout parameters first, and also set the scrolling direction to scroll horizontally, the size of the cell is the size of the screen &NBsp;4.3 Add a ScrollView (Tabbar bar) to the controller view above The Y value of ScrollView starts at 64 because there is also a navigation bar 4.4 Add sub-controller (add to Uiviewcontriller) The content of the button is determined by the corresponding sub-controller, when creating the sub-controller, to determine the contents of the button 4.5 Add caption button (add to ScrollView above) To bind the button tag, click on the button, remove the previous button corresponding controller, add the current button corresponding controller, and record the currently selected button NOTE: If a controller's view is added to the view of the B controller, Then a controller must be a sub-controller of the B controller 5. Display cell 5.1 set cell size equals screen size, set horizontal scrolling error, vertical scrolling no error, why? Error: Bug:the Item height must is less than the height of the Uicollectionview minus the section insets Top and bottom values Analysis: Reason: cell height must be less than or equal to colllectionview height-(top + bottom) &NB Sp  IOS7, the navigation controller adds an additional scrolling area to the top of the uiscrollview inside it   Solution: Remove the scrolling area that the system automatically adds 5.2 when scrolling around, there is space between cells, how to resolve & nbsp Cancel cell line spacing and column spacing layout.minimuminteritemspacing = 0; &nb Sp layout.minimumlinespacing = 0; 5.3 When you click the button to switch the interface, we find that the cell is Nill, Why? Click the button switch interface does not call the Uicollectionview data source method, only when the screen scrolling to call the data source method WORKAROUND: In the method of clicking the button, change the offset of CollectionView, let him offset to the specified position 5.4 switch interface, find or not call the data source method? Because the view we've previously added to the controller has been written in the method of clicking the button. &NBS P Click the button while the cell will scroll, but there will be a delay, not in time to call the data source method, How to fix? We write the code to add the controller view after the cell is created, so that there is a cell we add the controller's view Write code to add controller view in the data source method 5.5 Scrolling cell sometimes displays two interfaces, we want to display only one interface, what to do? &NBsp turn on Uiscrollview's paging function to solve the Uicollectionview inherits Uiscrollview, so all of Uiscrollview's properties and methods can be scrolled to the last page with 5.6, and you'll find that you can roll back Just bounce back, how to fix? Close the spring effect 5.7 found TableView above and below is blocked ( The navigation bar and Tabbar Bar are blocked) Add an inner margin to tableview top and bottom 5.8 the No. 0 button is selected by default 6. Add an underscore (caption indicator) 6.1 with what controls to use as an underscore Use view to be able to 6.2 Underline add to where? underline is used to indicate that the button is selected, and button related, add to the button inside can be? not, Ask for an underscore only one, there are multiple buttons, do not meet the requirements can be added to the parent control where the button is located (title bar ScrollView) 6.3 where to add? underline and button and ScrollView, then you should add more when you set the title bar and button, the button. Underline only needs to be added once, Default Check the first button method will only be called once, can be written in here  6.4 underlined frame how to set? underlined CenterX always and CenterX of the selected button Underline height According to the needs of our own set height determination, Y value also determines the = parent control height-own height underline width equal to the height of the button text &nbs P underlinev.xt_width = btn.titlelabel.xt_width; 6.5 Set underline, run does not display, Why? A control is not displayed generally there are three reasons: 6.5.1 no frame 6.5.2 blocked 6.5.3 is hidden We look through the bun, can't find the underscore control, exclude blocked and hidden possible 6.6 Print underline frame, find width of 0, why? We are adding a button in the Viewdidload method, although the button is set to frame, but the button inside the child control has no size, In the Viewdidlayoutsubviews method, size We want to manually calculate Btn.titlelabel width 6.7 How to calculate the width of the Btn.titlelabel
nsdictionary *nameattr = @{ Nsfontattributename: [Uifont systemfontofsize:15]}; [Btn.titleLabel.text sizewithattributes: nameattr]; outdated methods [Btn.titleLabel.text sizewithfont:[uifont systemfontofsize:15]]; Calculate a text height: Constrainedtosize width and maximum height of text [ Btn.titleLabel.text Sizewithfont:[uifont systemfontofsize:15] Constrainedtosize:cgsizemake (355, maxfloat)]; 7. Monitoring CollectionView scrolling complete 7.1 how to monitor? Set proxy uicollectionview inherit Uiscrollview, so Uiscrollview proxy method can be used -(void) Scrollviewdidenddecelerating: (Uiscrollview *) scrollview 7.2 scrolling finish to make the corresponding caption button selected, how to implement? First to get the button According to the controller can find the corresponding button 7.3 How to get the current controller? &NB Sp offset/width of each view = Current page (rounding) page number corresponds to the first controller 7.4 button How to get? &NBSP ; First think of the ScrollView from the button parent control, but we might get the underscore control, not line We need to define an array, To save all the buttons, you can get the desired button from the array NOTE: The array must be lazy to load (initialize), and use the point syntax (call set method) 7.5 Get the button, call the button to select the state method, let the button be selected 7.6 scroll complete, how to let the underscore (indicator) also follow the move? scroll complete, The method that will invoke the button check state, in this method set underline CenterX always equal to the current button CenterX can be  8. Package essence Framework (similar to the mainstream interface with Miss-no-sister) 8.1 Why draw a frame? Such a mainstream interface that many apps need, packaged up for easy reuse 8.2 How to package? Encapsulation Prerequisites: reusability Extensibility The extraction of a base class that encapsulates a framework-specific approach and implementation into a base class (for example: Setting the title bar and the caption button, CollectionView, etc.) We use it as long as it inherits from this base class, adding the controller we need is a simple way to 8.3 encapsulation If not, copy all the code to the base class &NBsp Some fixed, can be determined dead in the base class inside Some of the uncertainty (for example: how many sub-controllers) in the subclass implementation, can let the user to expand the 8.4 Inherit the base class to achieve the main interface of the building, found that the title bar can not be displayed, why? Title bar caption button is based on the corresponding sub-control to set the After we call the parent class (base class) Viewdidload, we add the self controller, that is, to set the button, in the Add Self controller Obviously, the title bar button is set to not succeed NOTE: To override the method of the parent class, be sure to call the Super method 8.5 How to set the title bar for normal display? & nbsp All we need to do is add the sub controller and then set the title bar Just write the button for the title bar in Viewwillappear. Imitate Uitabbarcontroller implementation principle) 8.6 set the title bar appears a bug, again to the same interface, the title bar has been reset again, how to resolve? Just get the title bar to load once, 8.7 to set the title bar, why not use the code once? Static dispatch_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{< #code to be executed once#>}); Once the code is called only once in the entire project, if there are two interfaces in this project to reuse the framework, then the second reuse of the framework of the controller can not set the title bar so that the framework has a vulnerability 8.8 how to only let the code execute once, but also can be reused? A property of type BOOL is defined in the base class that records that the method has not been executed-(void) Viewwillappear: (BOOL) animated
{[Super viewwillappear:animated]; if (_isinitial = = NO) {
Add Caption Button
[Self Setupalltitlebutton];
_isinitial = YES; }}
Main interface building principles (similar to the Master interface of Miss no sister)