Ios 在spotify中创建过渡和动画

Ios 在spotify中创建过渡和动画,ios,swift,xcode,animation,Ios,Swift,Xcode,Animation,我如何在spotify中创建这样的应用程序内转换,当我向下滚动时,按钮会向上移动,直到到达视图顶部?我还想知道如何创建平滑改变位置和尺寸的视图。 以下是spotify的截图: 一种方法是将按钮从ScrollView中取出,并在scrollViewDidScroll事件中更新其位置。您可以通过扩展UIScrollViewDelegate(或UITableViewDelegate,UICollectionViewDelegate的UICollectionViewDelegate和UICollecti

我如何在spotify中创建这样的应用程序内转换,当我向下滚动时,按钮会向上移动,直到到达视图顶部?我还想知道如何创建平滑改变位置和尺寸的视图。 以下是spotify的截图:

一种方法是将按钮从ScrollView中取出,并在
scrollViewDidScroll
事件中更新其位置。您可以通过扩展
UIScrollViewDelegate
(或
UITableViewDelegate
UICollectionViewDelegate
UICollectionViewDelegate
UICollectionViews
)来实现此事件

例如:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
   let yOffset = scrollView.contentOffset.y
   let newPossition = max(scrollableButtonTopConstraint.constant - yOffset, self.minimumPosition)
   self.scrollableButtonTopConstraint.constant = newPossition
}
在这里,
minimumPosition
是一个常量,用于防止按钮升高。您应该将其设置为适用于您的情况的值。另外,不要忘记在scrollview上设置委托,并为
scrollableButtonTopConstraint
创建一个出口