Home>

viewcontroller page jump

When jumping from one controller to another, there are generally two types:

1. Use uinavigationcontroller to call pushviewcontroller to jump;This method of pushing and popping,Perform controller management. Call popviewcontrolleranimated method to return.

pickimageviewcontroller * ickimageviewcontroller=[[pickimageviewcontroller alloc] init];
 [self.navigationcontroller pushviewcontroller:ickimageviewcontroller animated:true];
 [ickimageviewcontroller release];

2. Use uiviewcontroller's own presentmodalviewcontroller to jump;Calling the dismissmodalviewcontrolleranimated method can return.

pickimageviewcontroller * ickimageviewcontroller=[[pickimageviewcontroller alloc] init];
 [self presentmodalviewcontroller:ickimageviewcontroller animated:yes];
//return
[self dismissmodalviewcontrolleranimated:yes];

present viewcontroller modally

First, the main purpose

The pop-up modal viewcontroller is a very useful technology in iOS.Some viewcontrollers provided by uikit for modal display, such as uiimagepickercontroller. The pop-up modal viewcontroller is mainly used in the following situations:

1. Collect user input information

2, temporarily present some content

3.Temporarily change the working mode

4. The direction of the corresponding device changes

5. Display a new view level

In these cases, the normal execution flow of the program will be temporarily interrupted.The main function is to collect or display some information.

Two concepts and common settings

1.presenting view controller vs presented view controller

we When we view view controller b modally in view controller a, a acts as the presenting view controller (pop-up vc), and b is the presented view controller (pop-up vc). The official documentation suggests that the two interact via delegates.If you have used uiimagepickercontroller to select photos or take photos from the system album,We can find that the interaction between the imagepickercontroller and the vc that pops it up is through uiimagepickercontrollerdelegate.So we use it in practical applications,It is best to follow this principle,Define the delegate in the popup vc, and then implement the proxy in the popup vc,In this way, the interaction between the two can be implemented more conveniently.

2. Modal presentation styles

By setting the modalpresentationstyle property of presenting vc, we can set the style when the view controller pops up,There are four styles,It is defined as follows:

typedef enum {
 uimodalpresentationfullscreen=0, uimodalpresentationpagesheet, uimodalpresentationformsheet, uimodalpresentationcurrentcontext,} uimodalpresentationstyle;

Uimodalpresentationfullscreen represents when the vc pops up, the presented vc is full screen,If the wantedfullscreenlayout of the popup vc is set to yes, it will be populated below the status bar.Otherwise it will not fill under the status bar.

Uimodalpresentationpagesheet represents that when the pop-up is pop-up vc, the height of the presented vc is the same as the current screen height,The width is the same as the screen width in portrait mode.The remaining uncovered area will be dimmed and prevent users from clicking,In this pop-up mode,The effect of uimodalpresentationfullscreen is the same when it is in vertical screen.When landscaped, both sides will leave darkened areas.

UimodalpresentationformsheetThe height and width of the presented vc will be smaller than the screen size.presented vc center display,Darkened areas are left around.

UimodalpresentationcurrentcontextThe pop-up method of presented vc is the same as the parent vc of presenting vc.

These four methods are all effective on the iPad.But on iphone and ipod touch, the system has always displayed presented vc in uimodalpresentationfullscreen mode.

3, modal transition style (animation style when popping up)

By setting the modaltransitionstyle property of the presented vc, we can set the style of the scene switching animation when the presented vc pops up,It is defined as follows:

typedef enum {
 uimodaltransitionstylecoververtical=0, uimodaltransitionstylefliphorizontal, uimodaltransitionstylecrossdissolve, uimodaltransitionstylepartialcurl,} uimodaltransitionstyle;

We can see that there are sliding in from the bottom,Flip into it horizontally,Cross-dissolving and page turning are available.These four styles are not limited by the device,That is, whether it is iPhone or iPad, the transition effect will be displayed according to the style we specified.

4, dismiss modal viewcontroller (disappeared vc)

Disappearing presented vc, we can do it by calling any of the following two functions

dismissmodalviewcontrolleranimated://will be deprecated,Deprecation
dismissviewcontrolleranimated:completion:

Who will call this method of disappearing presented VC:The correct approach is "who pollutes who governs", that is, presenting vc calls the above method to cancel the display of presented vc. There is a benefit to doing this,If a VC does not pop up different view controllers with different choices made by the user, when it is no longer necessary to display the popped up view controller, call [self dismissmodalviewcontrolleranimated] directly to make it disappear.It doesn't matter which type of view controller it displays. Of course the system is optimized here,When we call the above method in presented vc,The system will automatically pass this message to the corresponding presenting vc, so that no matter who pops up,The ability to disappear when no longer needed.It depends on the specific situation in the application.If the presented vc needs to pass data with the presenting vc,It is recommended to dismiss the pop-up view controller in the proxy function implemented by presenting vc.

ios
  • Previous Tutorial for writing GUI dialogs in Java
  • Next Detailed mouse event design in Java graphical programming