zoukankan      html  css  js  c++  java
  • iOS 程序切换后台

    1.

    -(void)animationFinished:(NSString*)animationid finished:(NSNumber*)finished
    context:(void*)context
    {
       if ([animationid compare:@"exitApplication"]==0) {
          exit(0);// 退出应用程序
           NSLog(@"stop");
        }
    }
    -(IBAction)exit:(id)sender
    {
       [UIViewbeginAnimations:@"exitApplication"context:nil];    //动画名称
        [UIViewsetAnimationDuration:6];
        [UIViewsetAnimationDelegate:self];
        [UIViewsetAnimationTransition:UIViewAnimationCurveEaseInOutforView:self.viewcache:NO]; // 动画方式
    //动画结束执行的操作
     [UIVie setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    
       self.view.bounds=CGRectMake(0,0, 0, 0);//动画结束
        [UIViewcommitAnimations];
        
    }

    2.

    - (void)exitApplication {
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        UIWindow *window = app.window;
        
        [UIView animateWithDuration:1.0f animations:^{
            window.alpha = 0;
            window.frame = CGRectMake(0, window.bounds.size.width, 0, 0);
        } completion:^(BOOL finished) {
            exit(0);
        }];
        
    }

    3.

    Q:怎样用代码方式退出IOS程序
    
           A:没有提供用于正常退出IOS应用的API。
    
           在IOS中,用户点击Home键来关闭应用。你的应用应该符合以下条件:它不能自行调用方法,而应采取措施与用户交互,表明问题的性质和应用可能会采取的行为,比如打开WIFI,使用定位服务等供用户选择确定使用;
    
           警告:不要使用exit函数,调用exit会让用户感觉程序崩溃了,不会有按Home键返回时的平滑过渡和动画效果;另外,使用exit可能会丢失数据,因为调用exit并不会调用-applicationWillTerminate:方法和UIApplicationDelegate方法;
    
    如果在开发或者测试中确实需要强行终止程序时,推荐使用abort 函数和assert宏;
  • 相关阅读:
    使用git pull文件时和本地文件冲突怎么办?
    Git回滚代码到某个commit
    PHP如何在页面中原样输出HTML代码
    git 创建本地分支、提交到远程分支
    php mysqli扩展之预处理
    htmlspecialchars() 函数过滤XSS的问题
    PHP json_encode里面经常用到的 JSON_UNESCAPED_UNICODE和JSON_UNESCAPED_SLASHES
    javascript学习笔记——Array
    javascript学习笔记——Object
    javascript的底层实现学习总结
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/4329103.html
Copyright © 2011-2022 走看看