[英]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.