label_win3=[[UILabel alloc] initWithFrame:CGRectMake(55, 358, 210,15)];
[email protected]"Click here";
label_win3.textColor=[UIColor cyanColor];
label_win3.backgroundColor=[UIColor clearColor];
label_win3.font=[UIFont fontWithName:@"Helvetica" size: 14.0];
label_win3.textAlignment=UITextAlignmentCenter;
label_win3.userInteractionEnabled=YES;
[self.view addSubview:label_win3];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentTouch = [touch locationInView:self.view];
if([touch view]==label_win3) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowRegistration" object:nil];}
}
-1
A
回答
2
UILabels應該也不能響應觸摸。
TextViews,TextFields和Buttons都響應觸摸。
如果您不確定特定UI元素是否可以進行用戶交互,請閱讀文檔。
+0
爲什麼不呢?我看到它具有.userInteractionEnabled屬性。 – lilzz 2011-05-28 00:18:04
1
有userInteractionEnabled
意味着觸摸傳遞給視圖。這並不意味着該視圖(UILabel
)與他們做了什麼。 UILabel是一個非常輕量級的類。如果您想對UILabel觸摸做出響應,請將其附加UIGestureRecognizer
,對其進行分類或使用自定義UIButton
。很多時候,UIGestureRecognizer
是最好的解決方案(儘管你應該儘可能使用UIButton
;它包含很多專門的行爲,這些行爲很難再現)。
無論如何,你沒有理由期待你的touchesBegan:withEvent:
會被調用。你沒有感動。 UILabel被觸動,並且其touchesBegan:withEvent:
被調用。然後,它沒有按照設計做這件事。
Jasarien也是正確的,你的問題是非常不完整和困惑,但我想我們已經拼湊在一起。
相關問題
- 1. UIContainerView事件後未響應觸摸iOS
- 2. 延遲觸摸響應
- 3. UIBarButtonItem沒有響應觸摸
- 4. CCMenuItemImage不響應觸摸!
- 5. UIActionSheet不響應觸摸
- 6. 觸摸響應事件ios4
- 7. ViewController沒有響應觸摸
- 8. UILabel有觸摸方法嗎?
- 9. 觸摸ID導致應用無響應
- 10. UIButton的加入,以查看未響應觸摸
- 11. 視圖和按鈕旋轉後未響應觸摸
- 12. UIPicker View在操作表上未完全響應觸摸
- 13. UIWebView沒有響應觸摸屏幕
- 14. UIView子類不響應觸摸
- 15. UIResponder vs UIGestureRecognizer觸摸事件響應
- 16. Sencha觸摸JSON的XML響應
- 17. UITableViewCell觸摸響應的延遲
- 18. Webview沒有響應觸摸事件
- 19. UIScrollView的一部分不響應觸摸
- 20. UIPageControl不響應觸摸,不改變點
- 21. 查看不響應後觸摸
- 22. UIScrollView對觸摸沒有響應
- 23. 煎茶觸摸 - Ajax請求(JSON響應)
- 24. 增加觸摸手勢區域爲UILabel
- 25. 檢測UILabel上的觸摸事件
- 26. 可可觸摸 - 自定義的UILabel
- 27. 閃爍的UILabel可可觸摸
- 28. UIButton未註冊觸摸
- 29. 未觸發觸摸和滑動事件
- 30. Android應用程序無法響應觸摸
認真嗎?你只是在那裏轉儲你的代碼而沒有任何解釋或暗示的問題?你相信我們是精神的嗎?您的代碼只說明一個事實:標籤不接受用戶交互。這是設計。標籤是標籤,而不是按鈕,你必須自己處理事件。如果您想要更多地考慮修改您的問題,以表明您至少爲您做出了一些努力。 – Jasarien 2011-05-28 00:02:25
爲什麼不呢?我看到它具有.userInteractionEnabled屬性。 – lilzz 2011-05-28 00:17:45
當然,我正在親自處理這個事件。那是什麼touchbegan方法使用。如果觸摸等價的label_win3視圖然後觸發一個動作。 – lilzz 2011-05-28 00:26:07