Modal Simple Introduction
First, a brief introduction
In addition to push, there is another way to switch the controller, that is modal
Any controller can be ⽰ out through the modal form.
Modal default effect: The new controller is drilled from the bottom of the screen until it covers the previous controller as ⽌
Second, code description
Create a new project to add windows and controllers to the application agent.
YYAPPDELEGATE.M file
Copy Code code as follows:
//
Yyappdelegate.m
01-modal
//
Created by Apple on 14-6-9.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYAppDelegate.h"
#import "YYViewController.h"
@implementation Yyappdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
1. Create the window and set the window frame
Self.window=[[uiwindow Alloc]initwithframe:[[uiscreen Mainscreen] bounds];
2. Set window background color to black
Self.window.backgroundcolor=[uicolor Blackcolor];
Create a navigation controller as a child controller
Yyviewcontroller *one=[[yyviewcontroller Alloc]init];
Self.window.rootviewcontroller=one;
3. Set Windows as the main window and display
[Self.window makekeyandvisible];
return YES;
}
@end
Open modal window
YYVIEWCONTROLLER.M file
Copy Code code as follows:
//
Yyviewcontroller.m
01-modal
//
Created by Apple on 14-6-9.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
#import "YYtwoViewController.h"
@interface Yyviewcontroller ()
When clicked, jump to the second interface
-(Ibaction) Jump2two: (UIButton *) sender;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
Do no additional setup after loading the view from its nib.
}
-(Ibaction) Jump2two: (UIButton *) Sender {
Create a new modal and eject
Yytwoviewcontroller *two=[[yytwoviewcontroller Alloc]init];
Wrap the navigation controller on the two to allow a pop-up modal window to have a navigation bar to place the return button
Uinavigationcontroller *nvc=[[uinavigationcontroller Alloc]initwithrootviewcontroller:two
];
[Self PRESENTVIEWCONTROLLER:NVC animated:yes completion:^{
NSLog (@ "Pop-up a modal Window");
}];
}
@end
Remove modal view
YYTWOVIEWCONTROLLER.M file
Copy Code code as follows:
//
Yytwoviewcontroller.m
01-modal
//
Created by Apple on 14-6-9.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYtwoViewController.h"
@interface Yytwoviewcontroller ()
@end
Copy Code code as follows:
@implementation Yytwoviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
Add a return button to the navigation bar
Self.navigationitem.leftbarbuttonitem=[[uibarbuttonitem alloc]initwithtitle:@ "return" style: Uibarbuttonitemstyleplain target:self Action: @selector (change)];
}
-(void) Change
{
Write click event to return button
Click the return button to remove the current modal window
[Self.navigationcontroller Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Remove modal window");
// }];
If a controller is presented in modal form, it can be invoked and the controller's sub controller let the controller disappear
[Self Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Remove");
}];
}
@end
third, the attention point
(1) Modal features: When the modal window pop-up (from the bottom up), the rear view is not point
(2) Pop-up controller view (in this way only one view can be popped)
Copy Code code as follows:
Create a new modal and eject
Yytwoviewcontroller *two=[[yytwoviewcontroller Alloc]init];
Wrap the navigation controller on the two to allow a pop-up modal window to have a navigation bar to place the return button
Uinavigationcontroller *nvc=[[uinavigationcontroller Alloc]initwithrootviewcontroller:two
];
[Self PRESENTVIEWCONTROLLER:NVC animated:yes completion:^{
NSLog (@ "Pop-up a modal Window");
}];
(3) Remove the view of the controller (two options are available)
Copy Code code as follows:
Write click event to return button
Click the return button to remove the current modal window
[Self.navigationcontroller Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Remove modal window");
// }];
If a controller is presented in modal form, it can be invoked and the controller's sub controller let the controller disappear
[Self Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Remove");
}];
4 hint in the actual development, if the relationship between the controller is close to the general use of navigation controller, if the relationship between the controller is not very close to use modal
Iv. Internal mechanisms
(1) After the popup, window has only one child view.
(2) Although the current interface is displayed in front of our time Twoview, but the window's root controller is still njviewcontroller, it does not switch window root controller, but only to change the window shown above the view.
(3) The removed view was not destroyed because the controller did not destroy it, so the controller's corresponding view was not destroyed.
(4) in the modal pop-up (after full display), in the method passed two as a parameter, the default is a controller strong reference to it.
(5) When the downward removal, as long as the dismiss method to call the controller to close the window, modal released.
(6) A modal window that usually pops up provides a navigation bar, and the quickest way for the interface to have a navigation bar is to wrap a navigation controller on it.
(7) If a controller is presented in the form of a modal. You can call the controller and the Controller's child controller to allow the controller to disappear.
v. Transmission of data
Project file Structure and storyboard
code example:
YYVIEWCONTROLLER.M file
Copy Code code as follows:
//
Yyviewcontroller.m
02-modal Window data transfer
//
Created by Apple on 14-6-9.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
#import "YYtwoViewController.h"
@interface Yyviewcontroller ()
@end
Copy Code code as follows:
@implementation Yyviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
}
-(void) didreceivememorywarning
{
[Super didreceivememorywarning];
}
/*
If the relationship between the controllers is relatively close to the general use of Uinavigationcontroller
If the relationship between the controllers is not very tight, you can use modal
*/
This method is called to pass the data to the modal window of the segue before jumping through the jump.
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender
{
Get the target controller.
Uinavigationcontroller *nav=segue.destinationviewcontroller;
Yytwoviewcontroller *two= (Yytwoviewcontroller *) Nav.topviewcontroller;
Passing Data
two.name=@ "Wen ding Ding";
}
@end
YYtwoViewController.h file
Copy Code code as follows:
//
YYtwoViewController.h
02-modal Window data transfer
//
Created by Apple on 14-6-9.
Copyright (c) 2014 itcase. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Yytwoviewcontroller:uiviewcontroller
@property (nonatomic,copy) NSString *name;
@end
YYTWOVIEWCONTROLLER.M file
//
Yytwoviewcontroller.m
02-modal Window data transfer
//
Created by Apple on 14-6-9.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYtwoViewController.h"
@interface Yytwoviewcontroller ()
@property (Weak, nonatomic) Iboutlet Uilabel *nametext;
@end
Copy Code code as follows:
@implementation Yytwoviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
Self.nametext.text=self.name;
Add a return button to the navigation bar
Self.navigationitem.leftbarbuttonitem=[[uibarbuttonitem alloc]initwithtitle:@ "return" style: Uibarbuttonitemstyleplain target:self Action: @selector (Black)];
}
-(void) Black
{
To remove a modal window
[Self Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "removed successfully!") ");
}];
}
@end
app Mainstream UI Framework architecture
First, simple example
Description: Use the app mainstream UI frame structure to complete a simple interface
Build the page effect:
Second, the construction process and attention points
1. Create a new project, remove the original controller, add the Uitabbarcontroller controller as the management controller
2. The control interface completes constructs
3. Note the point:
(1) Hidden toolbar: Configure a property, Hideabotton bar in the push of the hidden bar at the bottom of the interface hidden, in which interface settings.
(2). Cell can set row height
(3) Wired
(4) Note: In the above page build directly use static cell, but in actual development, usually do not do so.
(5) Add Headerview to TableView (show a blue line)
three, app mainstream UI frame structure
Excuse me: Uitabbarcontroller and navigation controller in the structure of the position can be intermodulation? (A navigation bar)
To set the controller association or problem, Tableviewcontroller the method of implementing the data source by default, and two controllers manage it in turn. About navigation bars. What is displayed on the navigation bar is determined by the stack top controller, with only one of the following navigation bars (the stack top controller is the Tabbar controller).
Supplementary Note: iOS7 full screen of the design
Print the hierarchy of controllers in iOS7:
Print the hierarchy of controllers in IOS6: