你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> IOS 回收鍵盤通用代碼

IOS 回收鍵盤通用代碼

編輯:IOS技巧綜合
[摘要]本文是對IOS 回收鍵盤通用代碼的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。

感覺IOS的鍵盤回收好累,所以封裝了一個通用一點的方法

-(IBAction)spbResignFirstResponder:(id)sender
{
    //    NSLogObj(sender);
    if (sender == NULL || [sender isKindOfClass:[UITapGestureRecognizer class]]) {
        if (self.view != NULL && self.view.subviews != NULL && self.view.subviews.count > 0) {
            for (UIView *item in self.view.subviews) {
                if ([item isKindOfClass:[UITextField class]] || [item isKindOfClass:[UITextView class]]) {
                    UITextField *textField_item = (UITextField *)item;
                    [textField_item resignFirstResponder];
                }
                
                [self spbResignFirstResponder:item];
            }
        }
    }else if ([sender isKindOfClass:[UIView class]]) {
        UIView *view_item = sender;
        if ([view_item isKindOfClass:[UITextField class]] || [view_item isKindOfClass:[UITextView class]]) {
            [view_item resignFirstResponder];
        }
        
        if (view_item.subviews != NULL && view_item.subviews.count > 0) {
            for (UIView *item in view_item.subviews) {
                [self spbResignFirstResponder:item];
            }
        }
    }
}
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved