iOS 程式切換後台

來源:互聯網
上載者:User

標籤:

1.

-(void)animationFinished:(NSString*)animationid finished:(NSNumber*)finishedcontext:(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宏;

 

iOS 程式切換後台

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.