2012-12-03 74 views
0

有沒有在iOS上從屏幕上刪除鍵盤的選項?在這種情況下,我使用Tabris(http://developer.eclipsesource.com/tabris/)和Java。在iOS中使用Tabris隱藏鍵盤

我的問題是,我使用兩個文本框輸入用戶/密碼組合。填充這些文本框並按下一個按鈕以繼續iOS中的鍵盤始終顯示,但我希望鍵盤不再出現。只有在我點擊某處後,鍵盤纔會消失。

回答

0

在Tabris,你可以通過設置它使用鍵盤(如org.eclipse.swt.widgets.Text)上控制對焦「打開」鍵盤編程。 要隱藏鍵盤,只需將焦點設置爲不需要鍵盤的控件,就像Textfield的父組合一樣。

在你的情況下,我會將al行添加到Button的SelectionListener中,以便將Focus設置爲Textfields的Parent,然後啓動登錄過程。

下面是一些代碼,發揮和理解對焦機構:

public class FocusTest implements EntryPoint { 

public int createUI() { 
    Display display = new Display(); 
    Shell shell = new Shell(display, SWT.NO_TRIM); 
    shell.setMaximized(true); 
    GridLayoutFactory.fillDefaults().applyTo(shell); 
    createContent(shell); 
    shell.open(); 
    //while (!shell.isDisposed()) { 
    // if (!display.readAndDispatch()) { 
    //  display.sleep(); 
    // } 
    //} 
    return 0; 
} 

private void createContent(final Composite parent) { 
    Button buttonSingleText = new Button(parent, SWT.PUSH); 
    buttonSingleText.setText("Focus on SingleText"); 
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(buttonSingleText); 

    Button buttonMultiText = new Button(parent, SWT.PUSH); 
    buttonMultiText.setText("Focus on MultiText"); 
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(buttonMultiText); 

    Button buttonNoFocus = new Button(parent, SWT.PUSH); 
    buttonNoFocus.setText("Loose Focus"); 
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(buttonNoFocus); 

    final Text singleText = new Text(parent, SWT.SINGLE); 
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(singleText); 

    final Text multiText = new Text(parent, SWT.MULTI); 
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(multiText); 

    buttonSingleText.addSelectionListener(new SelectionAdapter() { 
     @Override 
     public void widgetSelected(SelectionEvent e) { 
      singleText.setFocus(); 
     } 
    }); 
    buttonMultiText.addSelectionListener(new SelectionAdapter() { 
     @Override 
     public void widgetSelected(SelectionEvent e) { 
      multiText.setFocus(); 
     } 
    }); 
    buttonNoFocus.addSelectionListener(new SelectionAdapter() { 
     @Override 
     public void widgetSelected(SelectionEvent e) { 
      parent.setFocus(); 
     } 
    }); 
} 
} 
+0

我試過的例子,但鬆動的焦點的按鈕無法正常工作。我在iPhone模擬器中嘗試了這一點,並且鍵盤不會隱藏。 – user1534567

0

您是否設置了UITextField委託並在其中添加以下方法?

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    return YES; 
}