美文网首页iOS 开发整理
App直接退出回到桌面界面

App直接退出回到桌面界面

作者: 流星载梦 | 来源:发表于2018-02-02 22:52 被阅读28次

    App直接退出回到主界面(非闪退,非崩溃)

    之前在群里看到有人问,不使用Home键,在应用中怎么让应用退出回到桌面,用闪退方法退出很容易但毕竟体验不好,之后看了几篇博客说添加个动画调用exit函数,然后试了一下效果是比闪退好,如果有更好的方法欢迎指教....


    方法一、

    - (void) ExitApp {
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        UIWindow *window = app.window;
        [UIView animateWithDuration:0.5f animations:^{
            window.alpha = 0.2;
            self.view.frame = CGRectMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height*0.7, 0, 0);
        } completion:^(BOOL finished) {
            exit(0);
        }];
    }
    

    方法二、

    - (void) ExitApp {
        [UIView beginAnimations:@"exitApplication" context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight  forView:self.view.window cache:NO];
        [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
        [UIView commitAnimations];
    }
    /**
     *  退出APP代码
     *  @param animationID animationID
     */
    - (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
        if ([animationID compare:@"exitApplication"] == 0) {
            exit(0);
        }
    }
    

    相关文章

      网友评论

        本文标题:App直接退出回到桌面界面

        本文链接:https://www.haomeiwen.com/subject/drdyzxtx.html