話不多說,直接上代碼
關(guān)閉所有鍵盤
- (void)hideKeyBoard
{
? ? ? for (UIWindow* window in [UIApplication sharedApplication].windows){
? ? ? ? ? ? ? for (UIView* view in window.subviews){
? ? ? ? ? ? ? ? ? ? ? ?[self dismissAllKeyBoardInView:view];
? ? ? ? ? ? ? }
? ? ? ?}
}
-(BOOL) dismissAllKeyBoardInView:(UIView *)view
{
? ? ?if([view isFirstResponder]){
? ? ? ? ? ? ? [view resignFirstResponder];
? ? ? ? ? ? ? return YES;
? ? ?}
? ? ?for(UIView *subView in view.subviews){
? ? ? ? ? ? ? if([self dismissAllKeyBoardInView:subView]) {
? ? ? ? ? ? ? ? ? ? return YES;
? ? ? ? ? ? ?}
? ? ?}
? ? return NO;
}
關(guān)閉ActionSheet、AlertView
- (void)closeModalView{
? ? ?for (UIWindow* window in [UIApplication sharedApplication].Windows){
? ? ? ? ? ? ?for (UIView* view in window.subviews){
? ? ? ? ? ? ? ? ? ?[self dismissActionSheetAndAletrtViewInView:view];
? ? ? ? ? ? }
? ? ? ?}
}
- (void)dismissActionSheetAndAletrtViewInView:(UIView*)view{
? ? ? ? ? ?if ([view isKindOfClass:[UIActionSheet class]]){
? ? ? ? ? ? ? UIActionSheet *actionView = (UIActionSheet *)view;
? ? ?[actionView dismissWithClickedButtonIndex:actionView.cancelButtonIndex animated:NO];
? ? ? ? ? ?}else if ([view isKindOfClass:[UIAlertView class]]){
? ? ? ? ? ? ? ? ? ? UIAlertView *alertView = (UIAlertView *)view;
? ? ?[alertView dismissWithClickedButtonIndex:alertView.cancelButtonIndex animated:NO];
? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ?for (UIView* subView in view.subviews){
? ? ? ? ? ? ? ? ? ? ? ? ?[self dismissActionSheetAndAletrtViewInView:subView];
? ? ? ? ? ? ? ? }
? ? ? ? ? }
}