2012-02-18 67 views
3

我有一個包含兩個文本框和一個登錄按鈕(layout:xbox)的簡單認證表單 當我編輯第一個文本框時,此表單完全適合鍵盤和狀態欄,但是當我切換到第二個文本框時,表單會向上滾動一下。當單擊文本框時防止表單向上滾動

問題:有誰知道如何防止滾動發生?

[編輯]代碼

app.views.UserLogin = function (config) { 
    Ext.apply(this, config); 

    this.loginField = new Ext.form.Text({ 
     cls: 'auth-login', 
     width:"100%", 
     allowBlank: false, 
     placeHolder:'Identifiant', 
     border:'0 0 1 0', 
    }); 

    this.passwordField = new Ext.form.Password({ 
     cls: 'auth-password', 
     width:"100%", 
     allowBlank: false, 
     placeHolder:'Mot de passe', 
     border:'0', 
    }); 

    this.loginBtn = new Ext.Button({ 
     width:"200px", 
     text: "Connect", 
     handler: this.onLoginBtnFn, 
     scope: this, 
     cls:'auth-button', 
    }); 

    this.authFieldSet = new Ext.form.FieldSet({ 
     width:"90%", 
     cls:'auth-fieldset', 
     items:[this.loginField,this.passwordField] 
    }); 

    //constructor 
    app.views.UserLogin.superclass.constructor.call(this, { 
     //dockedItems: [this.toolbar], 
     fullscreen: true, 
     cls:'auth', 
     layout: 'vbox', 
     items: [ 
      this.authFieldSet, 
      this.loginBtn 
     ] 
    }); 
}; 

感謝

回答

0

你能不能給我們一些更多的信息?滾動視圖中的表單是否正在向上移動?可能設置滾動= NO;也許有些代碼會有所幫助。

只是爲了說明我在談論iOS開發,我剛剛發佈,你不指定如果你在Objective-C中工作。

讓我稍微備份我的答案,這樣才更有意義。視圖控制器應該使用這些代理你可能已經這樣做了。使用文本字段委託可以訪問 - (void)textFieldDidBeginEditing:(UITextField *)發件人和 - (void)textFieldDidEndEditing:(UITextField *)textField方法。當ttext字段開始編輯時,您可以設置scrollingEnabled = NO,當文本字段結束編輯時,您可以設置scrollingEnabled = YES。這將是這個樣子:

-(void)textFieldDidBeginEditing:(UITextField *)sender 
{ 
self.currentTextField = sender; 
self.scrollView.scrollingEnabled = NO; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
self.currentTextField = nil; 
self.scrollView.scrollingEnabled = YES; 
} 

OR

另一種選擇是添加一個觀察者,如果您使用TextViews代替的TextField(或兩者的混合物),這是有用的。

- (void)viewWillAppear:(BOOL)animated 
{ 
[super viewWillAppear:animated]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:self.view.window]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
[_currentTextField resignFirstResponder]; 
[super viewWillDisappear:animated]; 
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 
} 

你做同樣的事情用這種方法,在keyboardWillShow方法停止滾動,並在keyboardWillHide方法再次啓動它。

希望我在幫助至少一點。

+1

scrolling = NO?這是從哪裏來的? – 2012-02-28 12:04:46

+0

對不起,延遲應對。您可以使用複選框在界面構建器中禁用滾動功能,或者使用編程功能(如有需要)禁用滾動功能: self.scrollView.scrollEnabled = NO; – RachelC 2012-03-08 16:31:55

+0

這將禁用整個Web視圖的滾動。我只想在輸入文本字段時禁用滾動功能。 – 2012-03-08 17:02:24