ISO給UIImageView增加點選事件

2022-02-02 00:14:33 字數 2449 閱讀 8668

自己做了乙個九宮格,裡面的圖示都是由多張重疊構成,然後包裝成乙個button來使用;

遇到的問題是如何給這個「button」增加點選事件?

解決思路1:網友提示在該「button」上增加乙個真正的透明button,這樣就可以順利執行點選事件了;但是本人嘗試發現,如果我調整了button的透明度後,點選是沒有效果的!可能是我操作錯誤,待再次驗證。

解決思路2:為uiimageview增加手勢

[imageview addgesturerecognizer:我們自己的手勢recognizer];

如何建立乙個手勢?看看uitapgesturerecognizer 的用法吧。

//單指單擊

uitapgesturerecognizer *singlefingerone = [[uitapgesturerecognizer alloc] initwithtarget:self

action:@selector(handlesinglefingerevent:)];

singlefingerone.numberoftouchesrequired = 1; //手指數

singlefingerone.numberoftapsrequired = 1; //tap次數

singlefingerone.delegate= self;

//單指雙擊

uitapgesturerecognizer *singlefingertwo = [[uitapgesturerecognizer alloc] initwithtarget:self

action:@selector(handlesinglefingerevent:)];

singlefingertwo.numberoftouchesrequired = 1;

singlefingertwo.numberoftapsrequired = 2;

singlefingertwo.delegate= self;

//雙指單擊

uitapgesturerecognizer *doublefingerone = [[uitapgesturerecognizer alloc] initwithtarget:self

action:@selector(handledoublefingerevent:)];

doublefingerone.numberoftouchesrequired = 2;

doublefingerone.numberoftapsrequired = 1;

doublefingerone.delegate= self;

uitapgesturerecognizer *doublefingertwo = [[uitapgesturerecognizer alloc] initwithtarget:self

action:@selector(handledoublefingerevent:)];

doublefingertwo.numberoftouchesrequired = 2;

doublefingertwo.numberoftapsrequired = 2;

doublefingertwo.delegate= self;

//如果不加下面的話,當單指雙擊時,會先呼叫單指單擊中的處理,再呼叫單指雙擊中的處理

[singlefingerone requiregesturerecognizertofail:singlefingertwo];

//同理雙指亦是如此

[doublefingerone requiregesturerecognizertofail:doublefingertwo];

[self.view addgesturerecognizer:singlefingerone];

[self.view addgesturerecognizer:singlefingertwo];

[self.view addgesturerecognizer:doublefingerone];

[self.view addgesturerecognizer:doublefingertwo];

[singlefingerone release];

[singlefingertwo release];

[doublefingerone release];

[doublefingertwo release];

處理事件的方法,**:

//處理單指事件

- (void)handlesinglefingerevent:(uitapgesturerecognizer *)sender

elseif(sender.numberoftapsrequired == 2)

} //處理雙指事件

- (void)handledoublefingerevent:(uitapgesturerecognizer *)sender

elseif(sender.numberoftapsrequired == 2)

}

給UIImageview 新增邊框 或者設定成圓角

設定layer calayer layer backview layer 是否設定邊框以及是否可見 layer setmaskstobounds yes 設定邊框圓角的弧度 layer setcornerradius 10.0 設定邊框線的寬 layer setborderwidth 1 設定邊框線...

給UIImageView新增點選事件

uiimageview imageview1 uiimageview alloc initwithframe cgrectmake 125,50,229,229 imageview1 setimage uiimage imagewithcontentsoffile path imageview1.u...

給UIImageView新增陰影和邊框

給uiimageview新增陰影和邊框 uiimageview iconview uiimageview alloc init 新增邊框 calayer layer iconview layer layer.bordercolor uicolor whitecolor cgcolor layer.b...