简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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