iOS Development UI Chapter-modal Brief Introduction

Source: Internet
Author: User

First, Brief introduction   In addition to push, there is another kind of controller switching mode, that is modal  any controller can be in the form of modal show? The default effect of  modal: The new controller drills up from the bottom of the screen, Until the controller is covered.?  II, Code description   Create a new project, add windows and controllers to the application agent.  YYAPPDELEGATE.M file   Copy code  1// 2// yyappdelegate.m 3// 01-modal 4//  5// created by Apple on 14-6-9. 6// copyright (c) 2014 itcase. All rights reserved. 7// 8  9 #import "YYAppDelegate.h" #import "YYViewController.h" 11 12 @implementation yyappdelegate13 14-(BOOL) Application: (UIApplication *) application Didfinishlaunchingwithoptions: (nsdictionary *) launchOptions15 {   //1. Create window and set frame17 for window     Self.window=[[uiwindow Alloc]initwithframe:[[uiscreen Mainscreen] bounds]];18    //2. Set window background color to black     Self.window.backgroundcolor=[uicolor blackcolor];20 21     22    //Create a navigation controller as a sub-controller for all     Yyviewcontroller *one=[[yyviewcontrolleralloc]init];24     self.window.rootviewcontroller=one;25     26    //3. Set window to main window and display     [Self.window makekeyandvisible];28     return yes;29}30 31 32 @ End Copy Code open modal window  yyviewcontroller.m file   Copy code  1// 2// yyviewcontroller.m 3//  01-modal 4// 5// created by Apple on 14-6-9. 6// copyright (c) 2014 itcase. All rights reserved. 7// 8  9 #import "YYViewController.h" #import "YYtwoViewController.h" 11  12 @interface Yyviewcontroller () 13//When clicked, jump to the second interface-(ibaction) Jump2two: (UIButton *) sender;15 16 @ End17 18 @implementation yyviewcontroller19 20-(void) viewDidLoad21 {    [super viewdidload];23     Additional setup after loading the view from its nib.24}25 26 27-(ibaction) Jump2two: ( UIButton *) Sender {   //Create a new modal and pop-up     YytwoviewcontroLler *two=[[yytwoviewcontroller alloc]init];30    //with navigation controller on both, so that the popup modal window has a navigation bar to put back the button up     Uinavigationcontroller *nvc=[[uinavigationcontroller alloc]initwithrootviewcontroller:two32                                  ];33     [self] PRESENTVIEWCONTROLLER:NVC animated:yes completion:^{34         NSLog (@ "Popup a modal Window"),    } ];36     37}38 @end Copy code remove modal view  yytwoviewcontroller.m file   Copy code  1// 2//  Yytwoviewcontroller.m 3// 01-modal 4// 5// created by Apple on 14-6-9. 6// Copy Right (c) 2014 itcase. All rights reserved. 7// 8  9 #import "YYtwoViewController.h" 10 11 @interface Yytwoviewcontroller () 12 13 @end14  15 @implementation yytwoviewcontroller16 17-(void) ViewDidLoad18 {     [Super viewdidload];20 21 &NBsp  //Add a Back button to the navigation bar.     Self.navigationitem.leftbarbuttonitem=[[uibarbuttonitem alloc]initwithtitle:@ "Back" Style:uibarbuttonitemstyleplain target:self action: @selector (change)];23}24 25-(void) Change26 {  & nbsp Write a click back button click events    //Click the Back button to remove the current modal window//   [self.navigationcontroller Dismissviewcontrolleranimated:yes completion:^{30//       nslog (@ "Remove modal window")//   }];     33//If a controller is shown in modal form, you can call the controller and the controller's sub-controller to let the controller disappear.     [Self Dismissviewcontrolleranimated:yes completion:^{35         NSLOG (@ "Remove"), +    }];37}38& nbsp;39 @end Copy Code Three, note point   (1) modal features: When the modal window pops up (from bottom to top), the rear view is not point   (2) The view of the popup controller (in this way can only pop up a view) copy code    //create a new modal and pop-up     Yytwoviewcontroller *two=[[yytwoviewcontroller alloc]init];   // With the navigation controller wrapped on both, let the popup modal window have a navigation bar to put back button     Uinavigationcontroller *nvc=[[uinavigationcontroller alloc]initwithrootviewcontroller:two                        &NBS P        ];    [self PRESENTVIEWCONTROLLER:NVC animated:yes completion:^{        NSLog (@ "Pop up a modal window");   }]; Copy code (3) Remove a view of the controller (two ways) copy the Code    //write click-to-Go button events    //Click the Back button to remove the current modal window//   [self.navigationcontroller Dismissviewcontrolleranimated:yes completion:^{/ /       nslog (@ "Remove modal window"),//   }];    //If a controller is shown in modal form, You can call the controller and the controller's sub-controller to let the controller disappear     [self dismissviewcontrolleranimated:yes completion:^{        NSLog (@ "Remove");   }]; Copy code (4) hint in the actual development, if the relationship between the controller is closely related to the general navigation controller, if the relationship between the controller is not very close to use the modal  four, After the internal mechanism (1) pops up, there is only one child view above the window. (2) Although the current interface is displayed in front of our eyes Twoview, but the window's root controller is still njviewcontroller, it does not switch the window's root controller, but simply to change the view shown above the window. (3) The removed view is not destroyed because the controller has not been destroyed, so the controller's corresponding view is not destroyed. (4) in the modal popup (after the full display), in the method passed in the parameter, the default isA controller strongly references it. (5) When removed, the modal is released as soon as the dismiss method of the controller is called to close the window. (6) The modal window usually pops up with a navigation bar, and the quickest way for the interface to have a navigation bar is to wrap it with a navigation controller. (7) If a controller is shown in modal form. You can call the controller and the controller's sub-controller to make the controller disappear.

iOS Development UI Chapter-modal Simple Introduction

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.