选中图片中的绿色部分,如何取消触摸?

How to cancel the touch when the green part in the image is selected?

我想让小船只在蓝色区域左右移动,而不能在绿色区域移动。当我触摸绿色区域时,船正在移动到那个位置。我不知道这是怎么回事,它应该只在蓝色区域移动。这是我的触摸开始和触摸移动:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch : UITouch = touches.first as UITouch!
    let loc_tmp = touch.location(in: self.view)


    location = CGPoint(x: loc_tmp.x, y: boat.center.y)
    boat.center = location


}
override func touchesMoved(_ touches: Set<UITouch>, with event: 
UIEvent?) {
    let touch : UITouch = touches.first as UITouch!
    let loc_tmp = touch.location(in: self.view)


    location = CGPoint(x: loc_tmp.x, y: boat.center.y)
    boat.center = location
}

假设绿色部分的宽度是widthGreen,船的宽度是boatWidth。

let clapmedX = min(view.frame.size.width - widthGreen - boatWidth / 2, max(loc_tmp.x, widthGreen + boatWidth / 2))
location = CGPoint(x: clapmedX, y: boat.center.y)
boat.center = location