2012-10-01 23 views

回答

2

這裏只是試圖解決方案,它希望有幫助

將下面的代碼添加到您的viewDidLoad;

-(void)viewDidLoad { 
    //create a tapGesture which calls a removeKeyboard method 
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeKeyboard)]; 

    tapGesture.cancelsTouchesInView = NO; 

    [self.yourScrollView addGestureRecognizer:tapGesture]; 
} 

-(void)removeKeyboard { 
    [self.yourTextField resignFirstResponder]; 
} 

希望幫助....

+0

謝謝你,先生,你是一個救世主.. – dcprog

1

試着在你看來下面的代碼...

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    if ([yourTextView isFirstResponder] && [touch view] != yourTextView) { 
     [yourTextView resignFirstResponder]; 
    } 
} 
+0

它不工作...我複製的代碼,並與我的文本框試了一下。但它不工作。而不是你的TextView,我用我的textFieldName。 – dcprog

+0

你的代碼有[touch view],但是我使用覆蓋整個UIView的UIScrollview – dcprog

+0

你的視圖是否設置爲你的UITextField的代表? – AndyDev