1、退出登录a
- (void)login
{
HomeViewController *homeVC = [[HomeViewController alloc]init];
[self presentViewController:homeVC animated:YES completion:nil];
}
- (void)exit
{
[self dismissViewControllerAnimated:YES completion:nil];
}
这是利用model形式登录和退出app的。当然登录的动画形式是多选的,你可以挑选一种喜欢的方式,你也可以自定义转场动画,这是你的自由。
/**
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal __TVOS_PROHIBITED,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
*/
这里我做了个gif动画,是关于系统自带的,可以看下:
2、登录退出b
- (void)login
{
HomeViewController *homeVC = [[HomeViewController alloc]init];
[self.navigationController pushViewController:homeVC animated:YES];
}
- (void)exit
{
[self.navigationController popViewControllerAnimated:YES];
}
这是利用导航控制器UINavigationController跳转。也是我们在项目中经常用到的一种方式,当然,登录退出也是常用这种方式的。这里就不过多去述。
3、更改 UIWindow 的 rootViewController
- (void)login{
HomeViewController *homeVC = [[HomeViewController alloc]init];
self.window.rootViewController = homeVC;
}
这个是写在AppDelegate中的,退出时再调用该方法。
4、退出app程序(不推荐使用,这种方式会让用户觉得app闪退)
- (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);
}];
}
警告 :不要使用exit函数,调用exit会让用户感觉程序崩溃了,不会有按Home键返回时的平滑过渡和动画效果;另外,使用exit可能会丢失数据,因为调用exit并不会调用-applicationWillTerminate:方法和UIApplicationDelegate方法;