第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

以編程方式將iPhone鍵盤頂部的工具欄對齊

以編程方式將iPhone鍵盤頂部的工具欄對齊

一只斗牛犬 2019-10-04 16:07:28
在某些情況下,我想在iPhone鍵盤的頂部添加一個工具欄(例如,在導(dǎo)航表單元素時,例如在iPhone Safari中)。目前,我正在使用常量指定工具欄的矩形,但是由于界面的其他元素在變動中-屏幕頂部的工具欄和導(dǎo)航欄-每次我們進行較小的界面更改時,工具欄都會偏離對齊狀態(tài)。有沒有辦法以編程方式確定鍵盤相對于當(dāng)前視圖的位置?
查看完整描述

3 回答

?
慕碼人2483693

TA貢獻1860條經(jīng)驗 獲得超9個贊

從iOS 3.2開始,有一種新方法可以實現(xiàn)此效果:

UITextFieldsUITextViews具有一個inputAccessoryView屬性,您可以將其設(shè)置為任何視圖,該屬性會自動顯示在上方并使用鍵盤進行動畫處理。

請注意,您使用的視圖既不應(yīng)位于其他視圖層次中,也不應(yīng)將其添加到某些超級視圖中,這是為您完成的。


查看完整回答
反對 回復(fù) 2019-10-04
?
皈依舞

TA貢獻1851條經(jīng)驗 獲得超3個贊

所以基本上:


在init方法中:


NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];

[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];

然后使用上面提到的方法來調(diào)整條的位置:


-(void) keyboardWillShow:(NSNotification *) note

{

    CGRect r  = bar.frame, t;

    [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];

    r.origin.y -=  t.size.height;

    bar.frame = r;

}

通過將位置變化動畫化,可以使其變得漂亮


    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:0.3];

//...

    [UIView commitAnimations];


查看完整回答
反對 回復(fù) 2019-10-04
?
HUH函數(shù)

TA貢獻1836條經(jīng)驗 獲得超4個贊

這基于tonklon的現(xiàn)有答案 -我只是添加一個代碼段,該代碼段在鍵盤頂部顯示一個半透明的黑色工具欄,并在右側(cè)顯示一個“完成”按鈕:


UIToolbar *toolbar = [[[UIToolbar alloc] init] autorelease];

[toolbar setBarStyle:UIBarStyleBlackTranslucent];

[toolbar sizeToFit];


UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)];


NSArray *itemsArray = [NSArray arrayWithObjects:flexButton, doneButton, nil];


[flexButton release];

[doneButton release];

[toolbar setItems:itemsArray];


[aTextField setInputAccessoryView:toolbar];

和-resignKeyboard看起來像:


-(void)resignKeyboard {

  [aTextField resignFirstResponder];

}

希望能對某人有所幫助。


查看完整回答
反對 回復(fù) 2019-10-04
  • 3 回答
  • 0 關(guān)注
  • 689 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號