The road long its repair far XI, I will go up and down and quest. It's a true portrayal of programmers.
Today, I would like to look at how to exit the project in iOS, and say that today, I have been concerned about it for a long time. I just can't find the way I think it's good. Today, I would like to make a list of what you know, and if you can find something better in the future, just add it.
Here is a code that we generally write about in the appdelegate of the project (as far as expansion and richness are, we are not going to delve into it):
-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
loginviewcontroller *LOGINVC = [[loginviewcontroller alloc] init];
Uinavigationcontroller *homenavigationview = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:LOGINVC];
Self.window.rootViewController = Homenavigationview;
self. Window. Rootviewcontroller = LOGINVC;
return YES;
}
Let's start our discussion around Loginviewcontroller, the login interface. We all know that the way to log in is different, will lead to the difference in the way of exit, there is login to exit, this is a causal relationship.
And we have no way to login in the form of these: the use of Modal to display the controller, using the navigation controller Uinavigationcontroller jump, of course, you can change the rootviewcontroller of UIWindow. Let's introduce these kinds of login methods.
1. Exit Login A
-(void) login
{
homeviewcontroller *HOMEVC = [[homeviewcontroller alloc]init];
[self presentviewcontroller: Homevc animated:YES completion: Nil];
}
-(void) exit
{
[self dismissviewcontrolleranimated:YES completion:nil];
}
This is logged in and out of the app using the model form. Of course the animated form of the login is multi-select, you can choose a preferred way, you can also customize the transition animation, which is your freedom.
/* * uimodaltransitionstylecoververtical = 0, uimodaltransitionstylefliphorizontal __tvos_prohibited, Uimodaltransitionstylecrossdissolve, uimodaltransitionstylepartialcurl ns_enum_available_ios (3_2) __TVOS_ Prohibited, * *
Here I made a GIF animation, is about the system comes with, you can look at:
2. Log Out B
-(void) login
{
homeviewcontroller *HOMEVC = [[homeviewcontroller alloc]init];
[self. Navigationcontroller pushviewcontroller: Homevc animated:YES];
}
-(void) exit
{
[self. Navigationcontroller popviewcontrolleranimated:YES];
}
This is the use of the navigation controller Uinavigationcontroller jump. is also a way we often use in the project, of course, sign-out is often used in this way. There is not much to be said here.
3, change the Rootviewcontroller of UIWindow
-(void) login{
homeviewcontroller *HOMEVC = [[homeviewcontroller alloc]init];
self. Window.rootviewcontroller = HOMEVC;
}
This is written in the Appdelegate, and then called when the method exits.
4, quit the app (not recommended, this way will let the user feel the app flash back)
-(void) exitapplication {
UIWindow *window = [uiapplication sharedapplication]. Keywindow;
[UIView animatewithduration:1.0f animations: ^{
Window. Alpha = 0;
Window. frame = cgrectmake(0, window. Bounds. Size. Width, 0, 0);
} Completion: ^ (BOOL finished) {
exit(0);
}];
}
warning : Do not use the Exit function, calling exit will make the user feel that the program crashes, there will be no smooth transitions and animations when the home key is returned, and that using exit may result in loss of data. Because calling exit does not call-applicationwillterminate: Methods and Uiapplicationdelegate methods;
Several ways to opt out of IOS app (project)