申し訳ありませんが...私はコードがあなたのために働く知ってみましょう古い。 あなたのUIViewのサブクラス指をスライドさせながら高さ制約を更新するために、元のタッチ位置
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { print("No touch"); return }
startPoint = touch.location(in: self)
startHeight = heightConstraint.constant
slideDirection = .none
super.touchesBegan(touches, with: event)
}
}
とtouchesMoved(_、と)を保存するtouchesBegan(_、有する)をオーバーライドすることができビュー。
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { print("touchesMovedno touches"); return }
let endPoint = touch.location(in: self)
let diff = endPoint.y - startPoint.y
// This causes the view to move along the drag
switch anchorLocation {
case .top :
heightConstraint.constant = startHeight + diff
case .bottom :
heightConstraint.constant = startHeight - diff
}
self.layoutIfNeeded()
// Update direction
if diff == 0.0 {
self.slideDirection = .none
} else {
self.slideDirection = (diff > 0) ? .down : .up
}
super.touchesMoved(touches, with: event)
}
オーバーライドtouchesEnded(_、と)あなたが
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
self.modifyHeightConstraints()
self.animateViewTransition(duration: animDuration, delay: animDelay, clearance: animClearance, springDampingRatio: animSpringDampingRatio, initialSpringVelocity: animInitialSpringVelocity, complete: {
self.slideDirection = .none
})
super.touchesEnded(touches, with: event)
}
をご希望の場合は、アニメーションを追加するために、私はあなたが望んでいた正確な機能を持っている可能性があるコンポーネントを作成しました。このコンポーネントには、調整可能なアニメーションバウンスが含まれています。ストーリーボードのビューで、サブビューのレイアウトやデザインを行うことができます。
私はあなたがまだ答えずにする必要があります私は私のコードを持っていないが、私は家を得るとき、私はそれを上に送信することができ、前にこれを行っているGitHubの
にhttps://github.com/narumolp/NMPAnchorOverlayView
をリンクをチェックアウト。 –
あなたの迅速な対応のために@JacobKingに感謝します。私はあなたの答えを待っています。 –
@JacobKingあなたはコード – user6520705