Main Interface construction principle (similar to the main interface of best thinking), main interface of elder sister

Source: Internet
Author: User

Main Interface construction principle (similar to the main interface of best thinking), main interface of elder sister

I. interface Setup 1. project requirements the main interface can scroll left and right, but also scroll up and down, click the button to jump to the interface 2. click the button on the Analysis page to jump to the page. You can customize UITabBarCotroller to scroll left and right. You can use scrollView to scroll up or down or UICollectionView. You can use tableView to implement 3. solution 1: UITabBarCotroller + scrollView + tableView + titleView (TabBar) UIScrollView disadvantages: scrollView is not used for off-screen rendering optimization, and tableView is rendered if not displayed, rendering is relatively memory-consuming, and many objects are created for off-screen rendering: if an interface is not displayed on the screen, it will not be rendered. If it is on the screen, it will render solution 2: UITabBarCotroller + UICollectionView + tableView + scrollView (TabBa R items) the benefits of the title UICollectionView can be extended: optimize off-screen rendering, instead of creating a cell where UITableView tableView is added to UICollectionView. 4. step 4.1 create a UIViewContriller 4.2 create UICollectionView add to UIViewContriller View create UICollectionView first set layout parameters and set scroll direction to horizontal scroll, the cell size is the screen size 4.3. Add a scrollView (TabBar bar) to the Controller's View. The y value of scrollView starts from 64, the content of the Add sub-controller (added to UIViewContriller) button in the navigation bar 4.4 is determined by the corresponding sub-controller. when creating the sub-controller, content 4.5 Add title button (added to scrollView) of the button to be confirmed) Bind a tag to the button. When you click the button, remove the Controller corresponding to the previous button, add the Controller corresponding to the current button, and record the currently selected button notes: if the View of controller A is added to the View of controller B, Controller A must be A sub-controller of controller B. it shows that the cell size set in cell 5.1 is equal to the screen size. If the horizontal scroll operation is set, an error is returned. If the vertical scroll is performed, no error is returned. Why? Error: bug: the item height must be less than the height of the UICollectionView minus the section insets top and bottom values analysis: cause: the cell height must be smaller than or equal to the height of colllectionView-(top + bottom) iOS7, the navigation controller will add an additional rolling area solution to the top of UIScrollView in it: how to cancel layout BETWEEN cell row spacing and column spacing when the auto-added rolling area is scaled around 5.2. minimumInteritemSpacing = 0; layout. minimumLineSpacing = 0; 5.3 When you click the button to switch the interface, the cell is found to be nill. Why? Click the button to switch the interface and the UICollectionView data source method will not be called. Only when the screen is scrolling will the data source method be called. Solution: in the method of clicking the button, change the offset of collectionView, let him offset to the specified position 5.4 switch interface, found or do not call the data source method? Because we have previously added the Controller's view and wrote it in the method of clicking the button. Although clicking the button will scroll the cell, there will be a delay and we cannot call the data source method in time. How can we solve this problem? We can write the code for adding the Controller view after creating the cell, in this way, we can add the Controller's view and write the code for adding the Controller view in the data source method. The 5.5 scroll cell sometimes displays two interfaces. What should we do if we want to display only one interface? Enabling the paging function of UIScrollView solves the problem that UICollectionView inherits UIScrollView. Therefore, all attributes and methods of UIScrollView can be rolled back to the last page with 5.6, how can this problem be solved? Disable the Spring Effect 5.7. You can see that the top and bottom of the tableView are blocked (the navigation bar and the TabBar bar are blocked). Add an inner margin 5.8 to the top and bottom of the tableView. By default, 0th buttons are selected. 6. add an underline (Title indicator) 6.1 what controls can be used as an underline and a View can be used. Where can I add a 6.2 underline? An underline is used to indicate that the button is selected. It is related to the button. Can it be added to the button? No. Only one underline is required. There are multiple buttons. If not, you can add them to the parent control where the button is located (title bar scrollView). Where can I add 6.3? The underline is related to the button and scrollView. You must add multiple buttons when setting the title bar and button. The underline only needs to be added once. By default, the method of selecting the first button is called only once, how can I set a frame with a 6.4 underline? The centerX of the underline is always the same as the centerX of the selected button. The underline height is determined based on our own settings, the y value is determined = parent control height-the height of the Self-configured underline width is equal to the height of the button text underLineV. xt_width = btn. titleLabel. xt_width; 6.5 is underlined and the running is not displayed. Why? A widget is not displayed for three reasons: 6.5.1 no frame 6.5.2 is blocked 6.5.3 is hidden. We can view it through the bread and cannot find the underline control, eliminate the possibility that the blocked or hidden frame may print an underline frame at 6.6 and the width is 0. Why? We add a button in the viewDidLoad method. Although frame is set for the button, the Child control in the button has no size. In the viewDidLayoutSubviews method, we need to manually calculate btn. how to calculate the btn of titleLabel width 6.7. titleLabel width NSDictionary * nameAttr ={ NSFontAttributeName: [UIFont systemFontOfSize: 15]};[Btn. titleLabel. text sizeWithAttributes: nameAttr]; expired method [btn. titleLabel. text sizeWithFont: [UIFont systemFontOfSize: 15]; Calculate the text Height: constrainedToSize text width and maximum height [btn. titleLabel. text sizeWithFont: [UIFont systemFontOfSize: 15] constrainedToSize: CGSizeMake (355, MAXFLOAT)]; 7. listen to collectionView rolling 7.1. How do I listen? Set the proxy UICollectionView to inherit UIScrollView, so the UIScrollView proxy method can use-(void) scrollViewDidEndDecelerating :( UIScrollView *) scrollView 7.2 to scroll to make the corresponding title button selected? First, you need to get the button. Based on the controller, you can find the corresponding button 7.3. How can you get the current controller? Offset/the width of each view = the current page number (rounded up) corresponds to the number of controller 7.4 buttons. How can this problem be obtained? First, we want to extract data from Subviews of scrollView, but we may get the underline control. If it is not feasible, 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 loaded (initialized), and you must use the dot syntax (call the set Method) 7.5 to get the button, call the button selection method to make the button to be selected 7.6 scroll complete, how to make the underline (indicator) also move? After the scrolling is completed, the method of selecting the button is called. In this method, the underlined centerX is always equal to the centerX of the current button. encapsulate the essence framework (similar to the mainstream interface of best thinking) 8.1 why should we extract a framework? Many such mainstream interfaces are required by apps. How can we encapsulate these interfaces to facilitate reuse? 8.2? Encapsulation premise: reusability scalability extracts a base class and encapsulates the methods and implementations specific to the Framework into the base class (for example, setting the title bar and title buttons, collectionView, etc) when we use it, as long as we inherit from this base class, adding the controller we need can be a simple method encapsulated by 8.3. If it does not, copy all the subclass code to the base class. If it is fixed, it will be retained into the base class with some uncertain things (for example, how many subcontrollers are there, users can extend 8.4 to inherit the base class to build the mainstream interface and find that the title bar cannot be displayed. Why? The title button of the title bar is set based on the corresponding sub-control. After calling viewDidLoad of the parent class (base class), we add the self-controller. That is to say, we set the button first, obviously, the title bar button cannot be set successfully. Note: to override the parent class method, you must call super method 8.5 to set the title bar to display it normally? You only need to set the title bar after adding the sub-controller. You only need to write the button for setting the title bar in viewWillAppear (imitating the implementation principle of UITabBarController) 8.6 A bug occurs when setting the title bar. The title bar is re-set again on the same page. How can this problem be solved? You only need to load the title bar once and set the title bar in 8.7. Why cannot I use the code once? Static dispatch_once_t onceToken;
Dispatch_once (& onceToken, ^ {<# code to be executed once #>}); a code is called only once throughout the project, if there are two interfaces in this project to reuse this framework, then the controller of the second reuse of this framework cannot be set as the title bar. As a result, the framework has a vulnerability 8.8. How can we only execute the code once and reuse it? Define a BOOL type attribute in the base class to record whether the method has been executed-(void) viewWillAppear :( BOOL) animated
{[Super viewWillAppear: animated]; if (_ isInitial = NO ){
// Add the title button
[Self setupAllTitleButton];
_ IsInitial = YES ;}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.