Я пытаюсь добавить жест панорамирования к своему виду, но я не знаю, почему он не хочет работать.Вот код моего 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!
, и мой метод жеста панорамирования выглядит следующим образом:
@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)