1.iOS代码退出程序一般直接调用exit(0); ,但是视觉上看起来像闪退,于是,我借鉴了下网上别人的代码,写了一个向下切出退出程序的方法,代码如下:
- (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);
}];
}
2.
//-------------------------------- 退出程序 -----------------------------------------//
- (void)exitApplication {
[UIView beginAnimations:@"exitApplication" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
// [UIView setAnimationTransition:UIViewAnimationCurveEaseOut forView:self.view.window cache:NO];
[UIView setAnimationTransition:UIViewAnimationCurveEaseOutforView:self.window cache:NO];
[UIViewsetAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
//self.view.window.bounds = CGRectMake(0, 0, 0, 0);
self.window.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);
}
}
本文介绍了一种在iOS应用中优雅退出程序的方法,通过动画效果使应用平滑退出,提供更好的用户体验。该方法涉及到UIView动画的使用,包括动画的开始、设置属性、动画完成后的回调以及动画的停止。
1万+

被折叠的 条评论
为什么被折叠?



