61

私はいくつかの iPhone アプリを開発するために PhoneGap を試しています。PhoneGap は基本的に UIWebView をラップします。うまく機能します。問題は、アプリに数値入力のみを受け取る入力フィールドがいくつかあることです。デフォルトの標準キーボードを受け入れる代わりに、数字キーパッドを強制的に使用する必要があります。これにより、ユーザーはすべてのフィールドで数字に切り替える必要があります。これが可能かどうか誰にもわかりますか?どのように?

明確化: Apple は現在、これを許可する API を提供していないことを知っています。UIWebView から継承したカスタム クラスを作成すると役立つか、カスタム キーボードを作成するといくつかの可能性が開けるかどうか疑問に思っています。

更新 2009 年 11 月 6 日 - 下記のとおり、Apple は最近サファリ機能を更新し、再びサポートされるようにしました。そのため、受け入れられた回答はそれを反映するように変更されました。

 <html>
<input type='tel'/>
<input type='number'/>
<input type='email'/>
<input />
</html>
4

10 に答える 10

73

Mobile Safariは、emailnumbersearchtel、およびurlの新しいHTML5入力タイプ属性をサポートしているようです。これらは、表示されるキーボードを切り替えます。type属性を参照してください。

したがって、たとえば、これを行うことができます。

<input type="number" />

また、入力ボックスにフォーカスがあると、数字キーボードが表示されます(ユーザーがフルキーボードを持っているかのように、「123」ボタンを押します。

本当に数字だけが必要な場合は、次のように指定できます。

<input type="tel" />

そして、ユーザーは電話番号ダイヤルキーパッドを取得します。

私はこれがMobileSafariで動作することを知っています-私はそれがUIWebViewで動作すると思います。

于 2009-10-01T18:57:12.590 に答える
29

<input type="text" pattern="[0-9]*">モバイル ブラウザーとデスクトップ ブラウザーの両方のフォームをデザインするときに使用するのが、より良い解決策であることがわかりました。

于 2013-04-22T23:42:54.147 に答える
4

IPhone OS 3.0でチェックしたところ、この機能はまだありませんでした。Appleがこの便利な機能を削除した理由がわかりません。今、これで動作することに本当に腹を立てています:(

于 2009-06-21T17:38:21.107 に答える
4

Apple のドキュメント(UIWebView に関するメモ)から:

入力要素でキーボードの種類を指定することはできません。Web ビューには、既定のキーボードに基づくカスタム キーボードが表示されますが、フォーム要素間を移動するための追加のコントロールが含まれています。

于 2009-04-21T20:25:41.323 に答える
3

iOS (4.0 以降) の Web ビューと互換性のあるすべてのタイプのリストを次に示します。

http://conecode.com/news/2011/12/mobile-safari-uiwebview-input-types/

于 2011-12-27T19:20:52.097 に答える
2

これは、iPhone OS の最初のイテレーションで可能でした - Safari は、名前に「zip」または「phone」を含むフォーム フィールドに数値キーボードを提供します - しかし、iPhone OS 2.0 ではそれがなくなりました。

PhoneGap には、現時点でこれをオーバーライドする API 関数がありません。それは彼らが取り組んでいるものかもしれません、それは間違いなく気の利いた機能になるでしょう.

于 2009-04-21T18:29:59.667 に答える
1

iOS phonegap ベースのアプリにも使用できるものは次のとおりです。

input type="number" pattern="[0-9]*"

それは下の画像に示されています。iOS 8.2 および phonegap 3.5 以降で美しく動作します。

于 2015-07-27T06:38:25.200 に答える
1

iOS Mobile Safari は以​​下もサポートしています。

<input type="password" />
于 2012-01-11T07:53:03.263 に答える
1

Dashcode プロジェクトの HTML 部分を変更する必要があります。

  1. Dashcode のコード ウィンドウで index.html を開きます。
  2. 作業中のビューのキャンバスで、最適化されたキーボードを使用するように設定する入力フィールドを選択します。
  3. index.html をクリックしてフォーカスします。
  4. ダッシュコード メニュー バーから [編集] > [検索] を選択します。
  5. テキスト フィールド コントロールに付けた正確な名前を検索ボックスに入力します。Find は index.html ファイル内のコントロールを見つけます。
  6. タイプを からtype="text"に変更しtype="number"ます。

終わり。

于 2010-10-13T04:04:07.937 に答える
0

iOS には数値キーボードがありますUIKeyboardTypeNumbersAndPunctuationが、これは HTML から呼び出すことはできません ( https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html )

「tel」キーボードでは句読点がないため、これを自分で作成する必要があります。iOS8以降、カスタムキーボードが利用可能です。または、句読点だけが必要な場合は、入力フィールドを で指定したときにポップアップする数値キーボードにボタンを追加できます ( iOS のテンキー キーボードに「完了」ボタンを追加する方法type="number" pattern="[0-9]*") 。

そのためには: Objective-C コード。

-(void)keyboardWillHide:(NSNotification *)note
{
    [self.donekeyBoardBtn removeFromSuperview];
    [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat: @"document.activeElement.blur()"]];
}

- (void)keyboardWillShow:(NSNotification *)note
{
    [UIView setAnimationsEnabled:NO];
    // create custom button
    //UIKeyboardTypeNumberPadin
    //type="number" pattern="[0-9]*"
    UIButton *extryB= [UIButton buttonWithType:UIButtonTypeRoundedRect];
    extryB.frame = CGRectMake(0, self.view.frame.size.height+150, 100, 50);
    extryB.backgroundColor = [UIColor colorWithRed:204.0f/255.0f
                                             green:210.0f/255.0f
                                              blue:217.0f/255.0f
                                             alpha:1.0f];
    extryB.adjustsImageWhenHighlighted = NO;
    extryB.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [extryB setTitle:@"," forState:UIControlStateNormal];
    [extryB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [extryB addTarget:self action:@selector(extryBpressed) forControlEvents:UIControlEventTouchUpInside];



self.donekeyBoardBtn = extryB;

// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++)
{
    keyboard = [tempWindow.subviews objectAtIndex:i];
    // keyboard view found; add the custom button to it

    if([[keyboard description] hasPrefix:@"<UIInputSetContainerView"] == YES)
    {

        for(int i = 0 ; i < [keyboard.subviews count] ; i++)
        {
            UIView* hostkeyboard = [keyboard.subviews objectAtIndex:i];

            if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES)
            {
                UIButton* donebtn = (UIButton*)[hostkeyboard viewWithTag:67123];
                if (donebtn == nil){
                    //to avoid adding again and again as per my requirement (previous and next button on keyboard)

                    if([[self printKeyboardType] isEqualToString: @"UIKeyboardTypePhonePad"]){
                        [keyboard addSubview:extryB];
                    }

                }
            }
        }
    }
    //[keyboard addSubview:extryB];
}
[UIView setAnimationsEnabled:YES];
// animate
[UIView animateWithDuration:0.5 animations:^{
    extryB.frame = CGRectMake(0, self.view.frame.size.height-50, 100, 50);
}];
}

-(NSString*)printKeyboardType
{

NSString* strKeyboardType = @"";
switch (self.textDocumentProxy.keyboardType) {
    case UIKeyboardTypeAlphabet:
        strKeyboardType = @"UIKeyboardTypeAlphabet";
        break;
    case UIKeyboardTypeDecimalPad:
        strKeyboardType = @"UIKeyboardTypeAlphabet";
        break;
    case UIKeyboardTypeDefault:
        strKeyboardType = @"UIKeyboardTypeDefault";
        break;
    case UIKeyboardTypeEmailAddress:
        strKeyboardType = @"UIKeyboardTypeEmailAddress";
        break;
    case UIKeyboardTypeTwitter:
        strKeyboardType = @"UIKeyboardTypeTwitter";
        break;
    case UIKeyboardTypeNamePhonePad:
        strKeyboardType = @"UIKeyboardTypeNamePhonePad";
        break;
    case UIKeyboardTypeNumberPad:
        strKeyboardType = @"UIKeyboardTypeNumberPad";
        break;
    case UIKeyboardTypeNumbersAndPunctuation:
        strKeyboardType = @"UIKeyboardTypeNumbersAndPunctuation";
        break;
    case UIKeyboardTypePhonePad:
        strKeyboardType = @"UIKeyboardTypePhonePad";
        break;
    case UIKeyboardTypeURL:
        strKeyboardType = @"UIKeyboardTypeURL";
        break;
    case UIKeyboardTypeWebSearch:
        strKeyboardType = @"UIKeyboardTypeWebSearch";
        break;
    default:
        strKeyboardType = @"UNKNOWN";
        break;
}
NSLog(@"self.textDocumentProxy.keyboardType=%@", strKeyboardType);
return strKeyboardType;
}

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

- (void)extryBpressed{
    //simulates a "." press
    [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat: @"simulateKeyPress('.');"]];
}

次に、JS コードでアプリケーション全体にアクセスできるメソッドを追加する必要があります。

simulateKeyPress: function(k) {
        var press = jQuery.Event("keypress");

        press.which = k;
        // place the id of your most outer html tag here
        $("#body").trigger(press);
            // just needed because my active element has a child element where the value should be placed in
                var id = document.activeElement.id.indexOf("-");
                if(id != -1){
                    var currentTf = sap.ui.getCore().byId(document.activeElement.id.split("-")[0]);
                    //append the value and set it (my textfield has a method setValue())
                    var currentTfValue = currentTf.getValue();
                    currentTf.setValue(currentTfValue + k);
                }
            },
于 2015-06-29T15:11:50.387 に答える