我正在尝试使用Hero-Framework实现此Tutorial中解释的动画。
目前,我位于教程中的步骤3上,用户应该可以在其中拖动视图。但是,这对我不起作用。这是我的代码:
// define a small helper function to add two CGPoints
func addCGPoints (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x + right.x, y: left.y + right.y)
}
// handle swqipe down gesture
@objc private func handlePan(gestureRecognizer:UIPanGestureRecognizer) {
switch panGR.state {
case .began:
// begin the transition as normal
dismiss(animated: true, completion: nil)
case .changed:
// calculate the progress based on how far the user moved
let translation = panGR.translation(in: nil)
let progress = translation.y / 2 / view.bounds.height
Hero.shared.update(progress)
// update views' position based on the translation
Hero.shared.apply(modifiers: [.position(addCGPoints(left: translation, right: self.wishlistBackgroundView.center))], to: self.wishlistBackgroundView)
Hero.shared.apply(modifiers: [.position(addCGPoints(left: translation, right: self.dismissWishlistViewButton.center))], to: self.dismissWishlistViewButton)
Hero.shared.apply(modifiers: [.position(addCGPoints(left: translation, right: self.menueButton.center))], to: self.menueButton)
default:
// end the transition when user ended their touch
Hero.shared.finish()
}
}
这是我设置ViewController
的方式:
view.addSubview(wishlistBackgroundView)
view.addSubview(dismissWishlistViewButton)
view.addSubview(menueButton)
wishlistBackgroundView.addSubview(wishlistView)
wishlistView.addSubview(wishlistLabel)
wishlistView.addSubview(wishlistImage)
wishlistView.addSubview(theTableView.tableView)
wishlistView.addSubview(addWishButton)
目前,如本教程所示,该视图不可拖动。 步骤1和步骤2可以很好地工作,但是以某种方式[根据翻译来更新视图位置]对我不起作用。 有人知道我在做什么错吗?如果还有更多需要说明的内容,请告诉我:)
我正在尝试使用Hero-Framework实现本教程中介绍的动画。目前,我处于教程的第3步,用户应该可以拖动视图。但是那个...