通过代码退出APP

建一个button

UIButton*button = [UIButtonbuttonWithType:UIButtonTypeCustom];

button.frame=CGRectMake(100,100,100,100);

button.backgroundColor= [UIColorredColor];

[buttonaddTarget:selfaction:@selector(exitApp)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:button];

点击:

-(void)exitApp

{exit(0);}

当然,你可以做一些动画。

-(void)exitApp

{

[UIViewbeginAnimations:@"exitApplication"context:nil];

[UIViewsetAnimationDuration:0.5];

[UIViewsetAnimationDelegate:self];

UIWindow*window = [UIApplicationsharedApplication].keyWindow;

[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:windowcache:NO];

[UIViewsetAnimationDidStopSelector:@selector(animationFinished:finished:context:)];

window.bounds=CGRectMake(0,0,0,0);

[UIViewcommitAnimations];

exit(0);

}

- (void)animationFinished:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {

if([animationIDcompare:@"exitApplication"] ==0) {

exit(0);

}

}

你可能感兴趣的:(通过代码退出APP)