假设屏幕上的每个 View 都显示有关特定日期的一些信息。向右滑动日期前进一天,向左滑动显示昨天的数据。
我已经设法通过捕获滑动手势并更新屏幕上的数据来实现这一点,但我没有得到滑动动画。我猜想这样做的正确方法是将 View Controller 连接到自身并进行更新,但我不确定。任何人都可以建议正确的方法吗?
最佳答案
每个方向都需要这样的方 block 。这是用于向右滑动(返回)。另一个方向相反。
UIView.animateWithDuration(NSTimeInterval(0.1), animations: {
//swipes view off screen
self.calView.frame.origin.x = self.view.frame.width
})
UIView.animateWithDuration(NSTimeInterval(0), delay: NSTimeInterval(0.1), options: UIViewAnimationOptions(rawValue: 0), animations: {
//jumps to other side
self.calView.frame.origin.x = -self.view.frame.width
}, completion: { _ in
//reload data, subtract one, whatever
self.setCurrentDate()
self.collectionView?.reloadData()
})
UIView.animateWithDuration(NSTimeInterval(0.1), delay: NSTimeInterval(0.2), options: UIViewAnimationOptions(rawValue: 0), animations: {
//swipes back to center
self.calView.frame.origin.x = 0
}, completion: nil)
关于ios - 我如何通过日期进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33694880/