简体   繁体   English

我如何通过日期进行排序?

[英]How do I segue through dates?

Imagine each view on the screen is to show some information about that particular day.想象一下,屏幕上的每个视图都显示了有关特定日期的一些信息。 Swiping right advances the date by one day, swiping left shows yesterday's data.向右滑动将日期提前一天,向左滑动显示昨天的数据。

I've managed to achieve this by capturing the swipe gesture and updating the data on the screen, but I don't get the swipe animation.我设法通过捕获滑动手势并更新屏幕上的数据来实现这一点,但我没有获得滑动动画。 I'm guessing the proper way to do this is to segue the view controller to itself and update instead but I'm not sure.我猜这样做的正确方法是将视图控制器与其自身进行连接并进行更新,但我不确定。 Can anyone advise on the proper way to do this?任何人都可以建议正确的方法来做到这一点吗?

You need a block like this for each direction.每个方向都需要一个这样的块。 This one is for Swipe Right (go back).这是用于向右滑动(返回)。 The other direction is reversed.另一个方向是相反的。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM