1976年贪婪的嘴唇,韩国少妇激三级做爰2023电影,久久久久久精品国产三级涨奶,妖精漫画在线观看免费漫画下拉式

iphone開發中給鍵盤加個隱藏工具條
來源:易賢網 閱讀:1333 次 日期:2014-11-18 11:16:29
溫馨提示:易賢網小編為您整理了“iphone開發中給鍵盤加個隱藏工具條”,方便廣大網友查閱!

因為iphone手機采用的觸摸涉及,本身沒有硬件鍵盤,一般都是點擊輸入框之后,彈出一個虛擬鍵盤出來,因此在iphone開發中,經常在完成編輯輸入之后,要寫程序代碼來關閉軟鍵盤的輸出,非常繁瑣,當然關閉軟鍵盤的方式有很多,比如放一個按鈕在底層,通過點擊屏幕的空白處來關閉鍵盤;也可以處理return鍵盤事件來關閉鍵盤,這些暫且不說,本文要分享的是一個鍵盤頂部工具條的類,通過這個工具條,可以很方便的關閉鍵盤,而且有上一項,下一項的輸入框切換,非常方便,效果請看下圖:

名單

類文件如下:

keyboardtopbar.h

//

// keyboardtopbar.h

//

//

// created by walkman on 10-12-2.

// copyright 2010 手機主題 all rights reserved.

//

#import

@interface keyboardtopbar : nsobject {

uitoolbar *view;//工具條

nsarray *textfields;//輸入框數組

bool allowshowpreandnext;//是否顯示上一項下一項

bool isinnavigationcontroller;//是否在導航視圖中

uibarbuttonitem *prevbuttonitem;//上一項按鈕

uibarbuttonitem *nextbuttonitem;//下一項按鈕

uibarbuttonitem *hiddenbuttonitem;//隱藏按鈕

uibarbuttonitem *spacebuttonitem;//空白按鈕

uitextfield *currenttextfield;//當前輸入框

}

@property(nonatomic,retain) uitoolbar *view;

-(id)init; //初始化

-(void)setallowshowpreandnext:(bool)isshow; //設置是否顯示上一項下一項

-(void)setisinnavigationcontroller:(bool)isbool; //設置是否在導航視圖中

-(void)settextfieldsarray:(nsarray *)array; //設置輸入框數組

-(void)showprevious; //顯示上一項

-(void)shownext; //顯示下一項

-(void)showbar:(uitextfield *)textfield; //顯示工具條

-(void)hiddenkeyboard; //隱藏鍵盤

@end

keyboardtopbar.m 文件

//

// keyboardtopbar.m

//

// created by walkman on 10-12-2.

// copyright 2010 手機主題下載all rights reserved.

//

#import keyboardtopbar.h

@implementation keyboardtopbar

@synthesize view;

//初始化控件和變量

-(id)init{

if(self = [super init]) {

prevbuttonitem = [[uibarbuttonitem alloc] initwithtitle:@上一項 style:uibarbuttonitemstylebordered target:self action:@selector(showprevious)];

nextbuttonitem = [[uibarbuttonitem alloc] initwithtitle:@下一項 style:uibarbuttonitemstylebordered target:self action:@selector(shownext)];

hiddenbuttonitem = [[uibarbuttonitem alloc] initwithtitle:@隱藏鍵盤 style:uibarbuttonitemstylebordered target:self action:@selector(hiddenkeyboard)];

spacebuttonitem = [[uibarbuttonitem alloc]initwithbarbuttonsystemitem: uibarbuttonsystemitemflexiblespace target:nil action:nil];

view = [[uitoolbar alloc] initwithframe:cgrectmake(0,480,320,44)];

view.barstyle = uibarstyleblacktranslucent;

view.items = [nsarray arraywithobjects:prevbuttonitem,nextbuttonitem,spacebuttonitem,hiddenbuttonitem,nil];

allowshowpreandnext = yes;

textfields = nil;

isinnavigationcontroller = yes;

currenttextfield = nil;

}

return self;

}

//設置是否在導航視圖中

-(void)setisinnavigationcontroller:(bool)isbool{

isinnavigationcontroller = isbool;

}

//顯示上一項

-(void)showprevious{

if (textfields==nil) {

return;

}

nsinteger num = -1;

for (nsinteger i=0; i<[textfields count]; i++) {

if ([textfields objectatindex:i]==currenttextfield) {

num = i;

break;

}

}

if (num>0){

[[textfields objectatindex:num] resignfirstresponder];

[[textfields objectatindex:num-1 ] becomefirstresponder];

[self showbar:[textfields objectatindex:num-1]];

}

}

//顯示下一項

-(void)shownext{

if (textfields==nil) {

return;

}

nsinteger num = -1;

for (nsinteger i=0; i<[textfields count]; i++) {

if ([textfields objectatindex:i]==currenttextfield) {

num = i;

break;

}

}

if (num<[textfields count]-1){

[[textfields objectatindex:num] resignfirstresponder];

[[textfields objectatindex:num+1] becomefirstresponder];

[self showbar:[textfields objectatindex:num+1]];

}

}

//顯示工具條

-(void)showbar:(uitextfield *)textfield{

currenttextfield = textfield;

if (allowshowpreandnext) {

[view setitems:[nsarray arraywithobjects:prevbuttonitem,nextbuttonitem,spacebuttonitem,hiddenbuttonitem,nil]];

}

else {

[view setitems:[nsarray arraywithobjects:spacebuttonitem,hiddenbuttonitem,nil]];

}

if (textfields==nil) {

prevbuttonitem.enabled = no;

nextbuttonitem.enabled = no;

}

else {

nsinteger num = -1;

for (nsinteger i=0; i<[textfields count]; i++) {

if ([textfields objectatindex:i]==currenttextfield) {

num = i;

break;

}

}

if (num>0) {

prevbuttonitem.enabled = yes;

}

else {

prevbuttonitem.enabled = no;

}

if (num<[textfields count]-1) {

nextbuttonitem.enabled = yes;

}

else {

nextbuttonitem.enabled = no;

}

}

[uiview beginanimations:nil context:nil];

[uiview setanimationduration:0.3];

if (isinnavigationcontroller) {

view.frame = cgrectmake(0, 201-40, 320, 44);

}

else {

view.frame = cgrectmake(0, 201, 320, 44);

}

[uiview commitanimations];

}

//設置輸入框數組

-(void)settextfieldsarray:(nsarray *)array{

textfields = array;

}

//設置是否顯示上一項和下一項按鈕

-(void)setallowshowpreandnext:(bool)isshow{

allowshowpreandnext = isshow;

}

//隱藏鍵盤和工具條

-(void)hiddenkeyboard{

if (currenttextfield!=nil) {

[currenttextfield resignfirstresponder];

}

[uiview beginanimations:nil context:nil];

[uiview setanimationduration:0.3];

view.frame = cgrectmake(0, 480, 320, 44);

[uiview commitanimations];

}

//釋放

- (void)dealloc {

[view release];

[textfields release];

[prevbuttonitem release];

[nextbuttonitem release];

[hiddenbuttonitem release];

[currenttextfield release];

[spacebuttonitem release];

[super dealloc];

}

@end

下面是使用這個類的代碼:

在uiviewcontroller頭文件中申明,并定義,并且實現uitextfielddelegate代理

比如:在keyboardtopbarviewcontroller.h文件,我是這樣寫的

//

// keyboardtopbarviewcontroller.h

// keyboardtopbar

//

// created by walkman on 10-12-2.

// copyright 2010 手機主題 all rights reserved.

//

#import

@class keyboardtopbar;

@interface keyboardtopbarviewcontroller : uiviewcontroller {

uitableview *tableview;

nsmutablearray *cellstextarray;

nsmutablearray *editfieldarray;

uibutton *btnreg;

keyboardtopbar *keyboardbar;

cgrect rect;

}

在在uiviewcontroller的m文件中,初始化,并添加到view中

- (void)viewdidload {

[super viewdidload];

......

//其中editfieldarray 是uitextfield數組,在上面已經初始化,并添加了n個uitextfield在里面。

//具體的代碼請下載附件查看,這里只貼出了相關的代碼

keyboardbar = [[keyboardtopbar alloc]init];

[keyboardbar setallowshowpreandnext:yes];

[keyboardbar setisinnavigationcontroller:no];

[keyboardbar settextfieldsarray:editfieldarray];

[self.view addsubview:keyboardbar.view];

}

//這個方法是uitextfielddelegate代理中的方法,表示輸入框開始處于編輯狀態。

- (void)textfielddidbeginediting:(uitextfield *)textfield{

[keyboardbar showbar:textfield]; //顯示工具條

......

}

ok了,調用起來還是很方便吧,當然,這個類還有需要完善的地方,比如,在執行了hiddenkeyboard方法隱藏了鍵盤和工具條之后,如果在調用頁面時候需要再做進一步處理,目前是無法實現的,等下一個版本中再加入一個delegate類。

更多信息請查看IT技術專欄

更多信息請查看技術文章
易賢網手機網站地址:iphone開發中給鍵盤加個隱藏工具條
由于各方面情況的不斷調整與變化,易賢網提供的所有考試信息和咨詢回復僅供參考,敬請考生以權威部門公布的正式信息和咨詢為準!

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
云南網警備案專用圖標
聯系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網
云南網警報警專用圖標
主站蜘蛛池模板: 大新县| 西昌市| 富蕴县| 泰顺县| 富平县| 吉木乃县| 南平市| 江安县| 镇坪县| 兰坪| 左云县| 永泰县| 将乐县| 漳州市| 积石山| 安国市| 迁西县| 新竹市| 伊宁市| 陕西省| 郁南县| 封丘县| 古田县| 梨树县| 顺平县| 玛多县| 兴义市| 钦州市| 平南县| 麻江县| 安乡县| 盱眙县| 黄骅市| 富源县| 监利县| 望奎县| 怀仁县| 加查县| 夏津县| 永济市| 城口县|