我有一个UIImageView,附带完美的UITapGestureRecognizer。这不是问题所在,但我添加的代码片段会添加手势以提供更多背景信息:
let tapGestureRecognizer = UITapGestureRecognizer(
target: self,
action: Selector("didTapImageView:")
)
imageView.addGestureRecognizer(tapGestureRecognizer)
imageView.userInteractionEnabled = true
这就是问题所在:ImageView位于ScrollView内部,根据设备调整其大小。调整大小也按预期工作,但是当它发生时,UIImageView不再识别轻击手势。一切都完美显示,但点击图像不会触发didTapImageView方法。仅在重新调整滚动视图时。
UIScrollView的大小调整发生在imagePickerController(picker, didFinishPickingMediaWithInfo)
委托方法中。这是:
let currentViewHeight = scrollView.frame.size.height
if currentViewHeight < heightLimit {
let frameRect = CGRect(x: 0, y: 0, width: self.view.frame.width, height: currentViewHeight + offset)
let frameSize = CGSize(width: scrollView.frame.size.width, height: currentViewHeight + offset)
scrollView.frame = frameRect
scrollView.contentSize = frameSize
}
如何防止手势识别器被取消?