標籤:
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 程式切換後台