[英]UITapGestureRecognizer does not respond to added subview in iOS7
在iOS7中,似乎沒有觸發以編程方式添加的子視圖上的手勢識別器,但是當以編程方式將手勢識別器添加到通過我的故事板界面添加的視圖時,手勢識別器不會觸發任何問題。 這曾經在iOS6中起作用,但突然停止在iOS7中起作用。 我做錯了什么或錯過了什么?
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomethingWhenTapped:)];
UIImageView *imageToTap = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Transparent" ofType:@"png"]]];
imageToTap.frame = CGRectMake(0, 0, 100, 100);
imageToTap.backgroundColor = [UIColor redColor];
[imageToTap addGestureRecognizer:tapGestureRecognizer];
[self.view addSubview:imageToTap];
編輯:
盡管我忘記在示例中添加userInteractionEnabled屬性(它是在我的真實代碼中設置的),但以下添加建議卻使我意識到我的真正問題是在橫向模式下遇到的奇怪的幀/邊界問題。
謝謝您的幫助!
UIImageView
默認情況下禁用了userInteractionEnabled
。 因此,您必須手動啟用它。
[imageToTap setUserInteractionEnabled:YES];
默認情況下,在UIImageView上禁用用戶交互。 嘗試將imageToTap.userInteractionEnabled = YES
設置imageToTap.userInteractionEnabled = YES
,看看是否適合您。 希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.