2012-05-23 79 views
3

我們爲iPad創建了自定義數字小鍵盤。在我們的測試人員iPad上,這個鍵盤突然移動出來,我們花了很長時間才發現可以通過在「鍵盤按鈕」通常位於的位置開始拖動來移動該自定義鍵盤。使自定義鍵盤不可移動

如果客戶意外移動它,客戶將很難將其移回。因爲在特定的輸入屏幕上移動鍵盤是沒有意義的,所以我寧願防止鍵盤移動,而不是繪製某種使用戶可以看到鍵盤可以移動的手柄。 (這是一個只編輯一個數字值的特殊輸入屏幕,鍵盤就像佈局的一部分,並且始終在此屏幕上可見)。

我努力嘗試,但是找不到防止鍵盤的方法在這個特定的地方拖動。即使我所有的骯髒的想法,例如刪除可能已有的GestureRecognizers(沒有)或將自己的按鈕放在前面也沒有幫助。

編輯: 鍵盤甚至可以在Monotouch中編寫的最簡單的自定義鍵盤應用程序中移動,我可以想到。我錯過了什麼嗎?

using System; 
using MonoTouch.Foundation; 
using MonoTouch.UIKit; 

namespace KeyboardTest 
{ 
    [Register ("AppDelegate")] 
    public partial class AppDelegate : UIApplicationDelegate 
    { 
     private UIWindow window; 
     private UIViewController viewController; 
     private UIViewController keyboardViewController; 

     public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
     { 
      window = new UIWindow (UIScreen.MainScreen.Bounds); 

      // Create a red dummy keyboard 
      keyboardViewController = new UIViewController(); 
      keyboardViewController.View.BackgroundColor = UIColor.Red; 

      // Create a textfield and assign our beautiful red keyboard as its InputView 
      UITextField textField = new UITextField(); 
      textField.BorderStyle = UITextBorderStyle.RoundedRect; 
      textField.Frame = new System.Drawing.RectangleF(44, 44, 200, 44); 
      textField.InputView = keyboardViewController.View; 

      // create a rootview controller and add our textfield 
      viewController = new UIViewController(); 
      viewController.View.AddSubview(textField); 

      window.RootViewController = viewController; 
      window.MakeKeyAndVisible(); 

      return true; 
     } 
    } 
} 

回答

1

對於你的解釋,我猜你有你的鍵盤作爲你的主視圖的子視圖。相反,我會將它設置爲UItextFields的inputView,然後使您的第一個textField成爲viewDidLoad上的第一響應者。喜歡的東西:

-(void)viewDidLoad{ 

[super viewDidLoad]; 

CustomkeyPad *keypad=[[CustomKeyPad alloc]init]; // initWithFrame would probably be better 

self.textField.delegate=self; 
self.textField.inputView=keypad; 
[self.textField becomeFirstResponder]; 

} 

我可不是在我的Mac,所以我在這裏提出一些可能的錯誤,但that's想法,That's我是如何做的,當我做我的自定義鍵盤以及和it' (iPad和iPhone)的橫向和縱向模式,到目前爲止它沒有給我帶來任何問題。

+0

感謝您的回答! 我的自定義鍵盤與示例代碼完全一樣,用作UITextfield的inputView。 您是否嘗試過在右下角拖動自定義鍵盤(就在那裏鍵盤鍵所在的位置)?如果您的自定義鍵盤不動,我會很驚訝。或者至少這將是非常不公平的;-) – manuel

+0

不,它不會移動。如果你想我可以發送給你的鍵盤項目。無論如何,我想把它提交給cocoacontrols。 – Marcal

+0

謝謝,這是慷慨的。如果你發佈它,我很高興看一看它。可能我錯過了Monotouch實現中的重要內容? – manuel