2012-03-02 74 views
2

我有這樣的代碼:UIView沒有出現在鍵盤上?

JMenuController *menuController = [[JMenuController alloc] init]; 
    NSArray *buttonsArray = [NSArray arrayWithObjects:@"From Libary", @"Take Photo or Video", nil]; 
    [menuController showMenuWithTitle:@"Add Media" ButtonTitles:buttonsArray animated:YES]; 
    self.currentMenuType = JCreateMenuTypeNewMedia; 

    [[[[UIApplication sharedApplication] delegate] window] addSubview:menuController]; 

的問題是,認爲出現的鍵盤,這已經是在屏幕下方。我該如何解決?

+1

被嚇了一會兒,我以爲甲骨文推出了「UISwing」! – doNotCheckMyBlog 2012-03-02 01:16:27

回答

1

OK了一段時間了,我聽不懂你想做的事。你有2個選項。

  • 退出鍵盤並用按鈕顯示視圖。

  • 使用UIActionSheet在鍵盤顯示按鈕像它在消息應用程序確實,當你按下相機將圖片發送給別人。

我會推薦以後。

編輯: 看看這個爲您定製UIActionSheet Show a view over the keyboard

+0

我基本上做了我自己的動作表,而不是使用默認的動作表。所以我想複製UIActionSheet的行爲。 – Andrew 2012-03-02 01:06:51

+0

@Andrew我更新了我的答案 – Bot 2012-03-02 01:09:59

1

鍵盤存在於它自己的窗口。把東西放在它上面,你必須把東西放到鍵盤的窗口中(這不是被支持的行爲),或者創建另一個窗口並將其放在鍵盤上。

+0

我該怎麼做? – Andrew 2012-03-02 01:07:30

+0

查看samvermette的回答。 – 2012-03-02 14:00:16

7

顯示在鍵盤的頂部一些人認爲最簡單的方法是把對你的windowLevel屬性設置爲UIWindowLevelAlert一個UIWindow內這一觀點。例如:

UIView *myView = [[UIView alloc] initWithFrame:rect]; 

UIWindow *myWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
myWindow.windowLevel = UIWindowLevelAlert; 
[myWindow addSubview:myView]; 

[myWindow makeKeyAndVisible]; 

如果您使用的是ARC,請確保您保留對myWindow的強烈參考。否則,它會自動發佈,因此它不會被添加到您的應用程序窗口中。

(這是UIActionSheet和U​​IAlertView中內部如何工作。當其中一人是可見的,看看[UIApplication的sharedApplication] .windows,你會看到他們創造的窗戶,他們的windowLevel設置爲UIWindowLevelAlert。)

+0

謝謝!那麼我也需要通過'[myWindow setHidden:YES]來隱藏它;' – Nianliang 2012-11-13 06:50:06

+0

謝謝!這對我很有用,但是一旦我解僱了我無法與我的用戶界面進行交互的視圖。在鍵盤中還有一個奇怪的行爲。我的焦點仍然在UItextField中,如果我按任意鍵,我的文本框中沒有改變,但如果我按退格鍵,我的文本被刪除。 – JiteshW 2013-05-09 09:45:47

+0

這對iOS 9不適用:( – Daniel 2015-11-25 15:22:50