博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
代码实现退出app
阅读量:4110 次
发布时间:2019-05-25

本文共 862 字,大约阅读时间需要 2 分钟。

有时候需要用代码的方式关闭程序,其实功能就像按了home键。

以下两种是可以通过认证的:

  1. [self performSelector:@selector(notExistCall)];  
  2. abort();  

下面两种是私有的,不能通过app store.

  1. [[UIApplication sharedApplication] performSelector:@selector(terminateWithSuccess)];   
  2. exit(0); 

但是通过这些方法退出的闪屏效果,会让用户觉得程序是crash了。所以我们可以添加一个动画效果,这样整个退出动作显得不是那么的唐突。

代码如下:

- (void)exitApplication {

    [UIView beginAnimations:@"exitApplication" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationCurveEaseOut forView:self.view cache:NO];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    self.view.bounds = CGRectMake(0, 0, 0, 0);
    [UIView commitAnimations];
}
- (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if ([animationID compare:@"exitApplication"] == 0) {
        exit(0);
    }
}

转载地址:http://siosi.baihongyu.com/

你可能感兴趣的文章
JavaSE_day_03 方法
查看>>
day-03JavaSE_循环
查看>>
Mysql初始化的命令
查看>>
day_21_0817_Mysql
查看>>
day-22 mysql_SQL 结构化查询语言
查看>>
MySQL关键字的些许问题
查看>>
浅谈HTML
查看>>
css基础
查看>>
HTML&CSS进阶
查看>>
Servlet进阶和JSP基础
查看>>
servlet中的cookie和session
查看>>
过滤器及JSP九大隐式对象
查看>>
软件(项目)的分层
查看>>
菜单树
查看>>
MySQL-分布式架构-MyCAT
查看>>
设计模式六大原则(6):开闭原则
查看>>
阿里面试总结--JAVA
查看>>
Servlet的生命周期
查看>>
JAVA八大经典书籍,你看过几本?
查看>>
《读书笔记》—–书单推荐
查看>>