我想显示一张地图并在其上添加一个可点击的图钉。地图上的手势识别器正在工作但不在引脚上。我尝试将UIGestureRecognizer和UIPinchRecognizer作为参数而没有。没有成功。
let imageSize = image.size ?? CGSizeZero
self.mapImage = UIImageView(image: image)
self.mapImage.frame = CGRect(origin: CGPoint(x: 0, y: 0), size:imageSize)
self.scrollView.addSubview(self.mapImage)
self.scrollView.contentSize = imageSize
var doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "scrollViewDoubleTapped:")
doubleTapRecognizer.numberOfTapsRequired = 2
doubleTapRecognizer.numberOfTouchesRequired = 1
self.scrollView.addGestureRecognizer(doubleTapRecognizer)
let scrollViewFrame = self.scrollView.frame
let scaleWidth = scrollViewFrame.size.width / self.scrollView.contentSize.width
let scaleHeight = scrollViewFrame.size.height / self.scrollView.contentSize.height
let minScale = min(scaleWidth, scaleHeight)
self.scrollView.minimumZoomScale = minScale
var image = UIImage(named: "MapPin")
var pinIcon = UIImageView(image: image)
pinIcon.userInteractionEnabled = true
pinIcon.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "buttonTapped:"))
let imageSize = image?.size ?? CGSizeZero
var xPosition : CGFloat = CGFloat(poi.x) - imageSize.width * 0.5
var yPosition : CGFloat = CGFloat(poi.y) - imageSize.height
pinIcon.frame = CGRect(origin: CGPoint(x: xPosition, y: yPosition), size: imageSize)
self.mapImage.addSubview(pinIcon)
self.view.sendSubviewToBack(self.scrollView)
答案 0 :(得分:0)
您需要设置UITapGestureRecognizer在针脚中点击所需的点击次数
var tap = UITapGestureRecognizer(target: self, action: "buttonTapped:")
tap.numberOfTapsRequired = 1
pinIcon.addGestureRecognizer(tap)
抱歉,我没有看到你在哪里使用捏,所以我无法帮助你