我试图在我的观点中添加潘手势,但我不知道为什么它不想工作。下面是我的UIView的代码:
self.infoView = UIView()
self.mapView.addSubview(infoView)
infoView.backgroundColor = .white
infoView.layer.cornerRadius = 10.0
infoView.layer.masksToBounds = true
infoView.isUserInteractionEnabled = true
infoView.translatesAutoresizingMaskIntoConstraints = false
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(self.moveInfoView(recognizer:)))
infoView.addGestureRecognizer(panGesture)我在我的UIViewController中将它定义为:
var infoView: UIView!我的pan手势方法看起来是:
@objc func moveInfoView(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translation(in: self.view)
if let view = recognizer.view {
view.center = CGPoint(x:view.center.x + translation.x,
y:view.center.y + translation.y)
}
recognizer.setTranslation(CGPoint.zero, in: self.view)
}我真的看不到我的错误。似乎一切都是正确的,但我似乎错了。你能指出我的错误吗?
更新
我的制约因素:
let constraints = [
// InfoView constraints
NSLayoutConstraint(item: infoView, attribute: .bottom, relatedBy: .equal, toItem: self.view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: infoView, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: infoView, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1.0, constant: 0.0),
infoViewHeightConstraint]哪里
let infoViewHeightConstraint = infoView.heightAnchor.constraint(greaterThanOrEqualToConstant: 112.0)发布于 2018-09-23 01:39:49
我怀疑问题在于您的观点是GMSMapView的一个子视图。地图视图已经添加了一组手势识别器,手势识别器回调被发送到GMSMapView实例,而不是您的子视图。尽管在settings上有一个GMSMapView属性,但它允许您为映射配置用户界面设置。尝试下面的代码来启用手势:
self.mapView.settings.consumesGesturesInView = false还有其他设置,您可以自定义那里。希望这能有所帮助
https://stackoverflow.com/questions/52460131
复制相似问题