通过动画的形式,完美实现应用的退出
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
[btn setTitle:@"退出" forState:(UIControlStateNormal)];
[btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
btn.frame = CGRectMake(100, 100, 100, 30);
btn.backgroundColor = [UIColor redColor];
[btn addTarget:self action:@selector(exitApplication) forControlEvents:(UIControlEventTouchUpInside)];
[self.view addSubview:btn];
}
- (void)exitApplication {
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[UIView beginAnimations:@"exitApplication" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:NO];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
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);
}
}