Swift-PanGestureRecognizer与Hero动画

时间:2020-01-09 22:50:14

标签: ios swift animation uipangesturerecognizer

我正在尝试使用Hero-Framework实现本Tutorial中所述的动画。

目前,我位于教程中的第3步,用户可以在其中拖动视图。但是,这对我不起作用。这是我的代码:

function removeEmptyRows(){
  var sh = SpreadsheetApp.getActiveSheet();
  var maxRows = sh.getMaxRows(); 
  var lastRow = sh.getLastRow();
  sh.deleteRows(lastRow+1, maxRows-lastRow);
}

这就是我设置// 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

目前,如本教程所示,该视图不可拖动。 第1步第2步可以很好地运行,但是以某种方式基于翻译更新视图位置对我不起作用。

有人知道我在做什么错吗?如果还有更多需要说明的内容,请告诉我:)

1 个答案:

答案 0 :(得分:0)

通过添加以下行对其进行了修复:

self.wishlistBackgroundView.hero.modifiers = [.fade, .translate(CGPoint(x: 0, y: 800), z: 20)]