我怎麼能隱藏滾動型觸摸事件鍵盤...上滾動型觸摸辭職急救員
的情況是這樣的...
- >查看 - >滾動型 - >文本字段
我想隱藏鍵盤上的scrollView。我試圖覆蓋滾動視圖的類,但我仍然無法做到這一點。
我怎麼能隱藏滾動型觸摸事件鍵盤...上滾動型觸摸辭職急救員
的情況是這樣的...
- >查看 - >滾動型 - >文本字段
我想隱藏鍵盤上的scrollView。我試圖覆蓋滾動視圖的類,但我仍然無法做到這一點。
做這樣將有助於:
@interface MyClass <UIScrollViewDelegate> {
}
@implementation
- (void)viewDidLoad {
yourScrollView.delegate = self;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[myTextField resignFirstResponder];
}
如果你真的要處理的觸摸事件,那麼你需要繼承的UIScrollView並重寫方法:
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
}
試試這個:
Add gesturereco gnizer用於滾動視圖,
UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
tapScroll.cancelsTouchesInView = NO;
[yourScrollview addGestureRecognizer:tapScroll];
[tapScroll release];
使用(tapped :)方法將鍵盤退出。
請看看這個答案,這是我找到的最簡單的答案。
UitextField resignFirstResponder does not work in scroll view
這是我在你的viewController的viewDidLoad法
UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapped)];
tapScroll.cancelsTouchesInView = NO;
[viewScroller addGestureRecognizer:tapScroll];
其中viewScroller是你的滾輪什麼工作
。在抽頭方法,我們有
- (void) tapped {
[self.view endEditing:YES];
}
不知道爲什麼,但上面並沒有爲我工作...即使它應該
是的,在iOSSDK中使用手勢後,這是一個很好的解決方案,由@ Dax解答。但是這個問題被問及很久沒有手勢的問題。但是myside的+1。 – 2012-10-22 04:29:36
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
[self.view endEditing:YES];
return YES;
}
我認爲你需要使用一個委託。 – mk12 2010-09-03 04:48:03
還有人可以幫我解決這個? – 2011-03-18 10:30:43