ios_21 Buy _ipad Neutron controller screen adaptation

Source: Internet
Author: User

Eventually:







Important screen fitting tips for your ipad ,

First add a contentview placeholder ,

And only set the frame in the viewdidload method ,

Because in the IPad , whether it's a horizontal or vertical screen , W is a narrow edge ,

So , first add a contentview to the right side of the host controller ,

And let it automatically scale with the main controller's width and height ,

The view of the sub-controller can only be added to contentview , x 0 y 0 wide is Contentview bounds



Code snippet:

mainviewcontroller.m//Handsome _ buy////Created by Beyond on 14-8-13.//Copyright (c) 2014 Com.beyond. All rights reserved.//Host Controller, the left side is the Dock, the right side is the sub controller #import "MainViewController.h" #import "Dock.h" #import "DockDelegate.h"// Custom Navigator #import The "four" button on the "BeyondNavigationController.h"//dock above the controller #import "DealListController.h" #import " MapController.h "#import" CollectionController.h "#import" MineController.h "@interface Mainviewcontroller () < dockdelegate>{//Important screen adaptation tips, first add a contentview placeholder, and only set the frame in the Viewdidload method, because the ipad, whether horizontal or vertical, W is a narrow edge, so Add a Contentview to the right side of the host controller and let it automatically scale with the main controller, while the sub-controller view is only added to Contentview, x 0 y 0 wide is contentview bounds UIView *_ Contentview;}    @end @implementation mainviewcontroller-(void) viewdidload{[Super Viewdidload];    Log (@ "%@", Nsstringfromcgrect (Self.view.frame));    Self.view.backgroundColor = [Uicolor Whitecolor];    1. Add the dock to the host controller [self adddock]; 2. Important screen adaptation techniques, first add a contentview placeholder, and only in the Viewdidload method to set the frame, because the ipad, regardless of the horizontal screen or vertical screen, W is a narrow edge, so first add a conTentview to the right side of the main controller, and let it automatically scale with the main controller, and the sub-controller view only add to Contentview, x 0 y 0 Wide is contentview bounds [self addcontentview];        3. Add all the sub-controllers, a total of 4, corresponding to the top 4 tab buttons in the dock [self addallchildcontrollers];    }//1. Add Dock to host Controller-(void) adddock{Dock *dock = [[Dock alloc] init];    The interior of the dock is set with height and right spacing, auto stretch, width also rewritten setframe fixed to Dock.frame = CGRectMake (0, 0, 0, self.view.frame.size.height);    When the column inside the dock is clicked, the proxy method can be called (The Block effect is the same) dock.delegate = self; [Self.view Addsubview:dock];} 1-1, implement the Dock proxy Method-(void) Dock: (Dock *) Dock tabchangefromindex: (int) FromIndex toindex: (int) toindex{log (@ "%d--clicked-%d    ", Fromindex,toindex);    1. First remove the old sub-controller (navigation wrapped) uiviewcontroller *OLDVC = Self.childviewcontrollers[fromindex];        [Oldvc.view Removefromsuperview];    2. Add a new sub-controller (navigation wrapped) uiviewcontroller *NEWVC = Self.childviewcontrollers[toindex]; 3. The sub-controller's view is added directly to the Contentview, and the wide-height auto-scaling, occupies full contentview, can complete the vertical screen and the horizontal screen to fit NewVC.view.autoresizingMask = Uiviewautoresizingflexibleheight | UIVIewautoresizingflexiblewidth;    Full Contentview, you can complete the vertical screen and horizontal screen to fit newVC.view.frame = _contentview.bounds;    [_contentview AddSubview:newVC.view]; }//2. Important screen adaptation tips, first add a contentview placeholder, and only set the frame in the Viewdidload method, because the ipad has a narrow edge regardless of the horizontal or vertical screen, so Add a Contentview to the right side of the host controller and let it automatically scale with the main controller, while the sub-controller view is only added to the Contentview, x 0 y 0 Wide is Contentview bounds-(void)    addcontentview{//Add Contentview to the right side of the host controller _contentview = [[UIView alloc] init];    Width of the main controller wide-dock width cgfloat contentvieww = SELF.VIEW.FRAME.SIZE.WIDTH-KDOCKITEMW;    Height for controller high cgfloat CONTENTVIEWH = self.view.frame.size.height; Important, wide and high both auto scaling _contentview.autoresizingmask = Uiviewautoresizingflexibleheight |    Uiviewautoresizingflexiblewidth; To set the Contentview frame once for the view did load only _contentview.frame = CGRectMake (KDOCKITEMW, 0, CONTENTVIEWW, CONTENTVIEWH    ); [Self.view Addsubview:_contentview];} 3. Add all the sub-controllers, a total of 4, and the Top 4 tab button in the dock corresponds to-(void) addallchildcontrollers{//1. Group Purchase _ sub-controller Deallistcontroller *DEALVC= [[Deallistcontroller alloc] init];    DealVC.view.backgroundColor = [Uicolor Purplecolor];    Beyondnavigationcontroller *nav = [[Beyondnavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:DEALVC];        [Self addchildviewcontroller:nav];    2. Map sub-controller Mapcontroller *MAPVC = [[Mapcontroller alloc] init];    MapVC.view.backgroundColor = [Uicolor Yellowcolor];    nav = [[Beyondnavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:MAPVC];        [Self addchildviewcontroller:nav];    3. Collection _ sub-controller Collectioncontroller *COLLECTIONVC = [[Collectioncontroller alloc] init];    CollectionVC.view.backgroundColor = [Uicolor Greencolor];    nav = [[Beyondnavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:COLLECTIONVC];        [Self addchildviewcontroller:nav];    4. My _ sub-controller Minecontroller *MINEVC = [[Minecontroller alloc] init];    MineVC.view.backgroundColor = [Uicolor Bluecolor];    nav = [[Beyondnavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:MINEVC]; [Self ADDCHILDVIEWCONTROLLER:NAV]; 5. And manually call the dock proxy method, the default is to select the Buy _ sub controller [self Dock:nil tabchangefromindex:0 toindex:0];} @end


custom navigation controller used:

beyondnavigationcontroller.m//Handsome _ buy////Created by Beyond on 14-8-14.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondNavigationController.h" @interface Beyondnavigationcontroller () @ End@implementation beyondnavigationcontroller//optimization, the first time you use this class, instantiate an object when called, and only call once + (void) initialize{//1.        The Appearance method returns the global appearance object of a navigation bar//modifies the Appearance object, which is equivalent to modifying the appearance of the entire project Uinavigationbar *navibar = [Uinavigationbar appearance]; 2. Set the background picture of the navigation bar (stretch one pixel from the center) [Navibar setbackgroundimage:[uiimage imagestretchedwithname:@ "Bg_navigation.png"] forBa        Rmetrics:uibarmetricsdefault]; 3. Set the navigation bar text theme [Navibar settitletextattributes:@{nsforegroundcolorattributename: [U                                  Icolor Blackcolor], nsshadowattributename: [Nsvalue Valuewithuioffset:uioffsetzero]        }];    4. Similarly, modify the global appearance of all uibarbuttonitem uibarbuttonitem *barbtnitem = [Uibarbuttonitem appearance];  Modify the background picture of item  [Barbtnitem setbackgroundimage:[uiimage imagestretchedwithname:@ "Bg_navigation_right.png"] forState:    UIControlStateNormal Barmetrics:uibarmetricsdefault]; [Barbtnitem setbackgroundimage:[uiimage imagestretchedwithname:@ "Bg_navigation_right_hl.png"] forState:        Uicontrolstatehighlighted Barmetrics:uibarmetricsdefault]; Modify the text style above the item nsdictionary *dict = @{nsforegroundcolorattributename: [Uicolor Darkgrayco                           Lor], nsshadowattributename: [Nsvalue Valuewithuioffset:uioffsetzero],    Nsfontattributename: [Uifont systemfontofsize:16]};    [Barbtnitem settitletextattributes:dict Forstate:uicontrolstatenormal];        [Barbtnitem settitletextattributes:dict forstate:uicontrolstatehighlighted]; 5. Set the status bar style [uiapplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;} @end



Dock View

dock.m//Handsome _ buy////Created by Beyond on 14-8-13.//Copyright (c) 2014 Com.beyond. All rights reserved.//The left side of the host controller is the dock, and the right side is the sub-controller corresponding to the dock column #import "Dock.h"//More buttons at the bottom of the dock #import "DockItemMore.h"// The bottom 2nd "positioning" button #import "DockItemLocation.h"//Dock top four buttons (Buy, Map, collection, my) use instances of this class #import "DockItemTab.h" #include " DockDelegate.h "@interface Dock () {//Dock top four buttons (Buy, Map, collection, my) the one that is lit to white (that is, the selected one, the picture is set to the disable state is white) Dockitemtab * _currenttab;}    @end @implementation dock-(ID) initWithFrame: (cgrect) frame{self = [super Initwithframe:frame];        if (self) {//1, set dock always on the left side of the main controller, as well as the background [self setdockpositionandbg];        2. Add the Buy logo on the top of the dock [self addlogo];        3. Add the "more" button at the bottom of the dock [self addmorebtn];        4. Add the bottom 2nd "position" button under the dock [self addlocationbtn];    5. Add four buttons at the top of the dock (Buy, map, Favorites, my) [self addfourtabbtn]; } return self;} 1, set the dock to always be on the left side of the main controller, as well as the background-(void) setdockpositionandbg{//1. Let the dock automatically scale (height + right spacing) Self.autoresizinGmask = Uiviewautoresizingflexibleheight |        Uiviewautoresizingflexiblerightmargin; 2. Set dock background color, tile with picture Self.backgroundcolor = [Uicolor colorwithpatternimage:[uiimage imagenamed:@ "Bg_tabbar.png"] ;}    2. Add buy logo-(void) addlogo{Uiimageview *logo = [[Uiimageview alloc] init] at the top of the dock;    Logo.image = [UIImage imagenamed:@ "Ic_logo.png"];    Set size CGFloat scale = 0.65;    CGFloat Logow = logo.image.size.width * scale;    CGFloat Logoh = logo.image.size.height * scale;    Center, set the width height first, then set the center point xy logo.bounds = CGRectMake (0, 0, Logow, Logoh);    Set Position Logo.center = Cgpointmake (kdockitemw*0.5, kdockitemh*0.5); [Self Addsubview:logo];}    3. Add the "more" button at the bottom of the dock-(void) addmorebtn{dockitemmore *morebtn = [[Dockitemmore alloc] init];    CGFloat y = self.frame.size.height-kdockitemh;    Because the Morebtn button is automatically scaled, always at the bottom of the dock, and its parent class has been internally fixed wide morebtn.frame = CGRectMake (0, y, 0, 0); [Self addsubview:morebtn];} 4. Add the bottom 2nd "position" button below the dock-(void) addlocationbtn{DockitemlocatIon *locbtn = [[Dockitemlocation alloc] init];    Because the Locbtn button is automatically scaled, always at the bottom 2nd of the dock, and its parent has been internally fixed wide cgfloat y = self.frame.size.height-kdockitemh * 2;    Locbtn.frame = CGRectMake (0, y, 0, 0);    loc.enabled = NO; [Self addsubview:locbtn];} 5. Add four buttons at the top of the dock (group 0, map 1, Favorites 2, my 3)-(void) addfourtabbtn{//1. Add a tabbtn (group purchase) [self addonetabbtn:@] using the extracted method IC_DEAL.P        Ng "selectedicon:@" ic_deal_hl.png "index:0";        2. Use the extracted method to add a tabbtn (map) [Self addonetabbtn:@ "ic_map.png" selectedicon:@ "Ic_map_hl.png" index:1];        3. Use the extracted method to add a tabbtn (favorite) [Self addonetabbtn:@ "ic_collect.png" selectedicon:@ "Ic_collect_hl.png" index:2];        4. Use the extracted method to add a tabbtn (my) [Self addonetabbtn:@ "ic_mine.png" selectedicon:@ "Ic_mine_hl.png" index:3];    5. Add the divider line at the bottom of the label uiimageview *dividerimgview = [[Uiimageview alloc] init];    Dividerimgview.frame = CGRectMake (0, KDOCKITEMH * 5, KDOCKITEMW, 2);   Dividerimgview.image = [UIImage imagenamed:@ "Separator_tabbar_item.png"]; [Self addsubview:dividerimgview];} 5-1, using the extraction method to add a tabbtn (group 0, map 1, Favorites 2, my 3), the parameter index determines the y value-(void) ADDONETABBTN: (NSString *) Iconname Selectedicon: ( NSString *) Selectediconname index: (int) index{//(group buy, map, Favorites, my) tabbtn use the same parent class, they just have a different y value dockitemtab *tab = [[Dockitemta    B alloc] init];    Set the button background and the selected picture [tab seticon:iconname Selectedicon:selectediconname];    Tab.frame = CGRectMake (0, KDOCKITEMH * (index+1), 0, 0); Because it is a tab, as long as the user fingers tap on the Trigger [tab addtarget:self Action: @selector (Tabbtnclick:) forControlEvents:    Uicontroleventtouchdown];    Tag 0 1 2 3 (buy 0, map 1, Favorites 2, my 3) Tab.tag = index;    [Self addsubview:tab];    The index = = 0 is selected by default (group 0, map 1, Favorites 2, my 3) if (index = = 0) {[Self tabbtnclick:tab]; }}//5-2, because the dock is added tab, so the dock is the task of listening tab Click, while the host controller added the dock, so the host controller must become the dock agent, the dock notifies its agent, tell the agent, its internal tab has been clicked-( void) Tabbtnclick: (Dockitemtab *) tab{//0. Because you want to pass two tags, you must first notify the dock agent (because the dock is added to the host controller, so the dock agent is the host controller) if ([_delegate Res Pondstoselector: @selector (Dock:tabchangefromiNdex:toindex:)] {//The method that invokes the proxy, which is equivalent to the notification agent, from which button in the self dock switches to which [_delegate dock:self tabchangefromindex:_cur    Renttab.tag ToIndex:tab.tag];    }//1. Control status//first put the previous gray, because the picture is set to enable the state is black _currenttab.enabled = yes;    Then put the point of this one white, the picture is set to disable state for the highlight white tab.enabled = NO; Finally, the button that is clicked is set to the current _currenttab = tab;}    #pragma mark 1, rewrite the Setframe method: default to its own width, to prevent external changes in width high-(void) Setframe: (cgrect) frame{frame.size.width = KDOCKITEMW; [Super Setframe:frame];} @end





















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.