Last active
February 14, 2017 10:39
-
-
Save anuraagdjain/231e2a4043e02c1535e423a0edabe3c4 to your computer and use it in GitHub Desktop.
Twitter Like Pull effect iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Source: https://github.com/ariok/TB_TwitterUI | |
| @IBOutlet weak var headerView: UIView! | |
| @IBOutlet weak var scrollView: UIScrollView! | |
| override viewDidLoad(){ | |
| scrollView.delegate = self | |
| /* | |
| Add below code for testing purposes. | |
| scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: 1024) | |
| */ | |
| } | |
| func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
| let offset = scrollView.contentOffset.y | |
| var headerTransform = CATransform3DIdentity | |
| if offset < 0 { | |
| let headerScaleFactor:CGFloat = -(offset) / headerView.bounds.height | |
| let headerSizevariation = ((headerView.bounds.height * (1.0 + headerScaleFactor)) - headerView.bounds.height)/2.0 | |
| headerTransform = CATransform3DTranslate(headerTransform, 0, headerSizevariation, 0) | |
| headerTransform = CATransform3DScale(headerTransform, 1.0 + headerScaleFactor, 1.0 + headerScaleFactor, 0) | |
| headerView.layer.transform = headerTransform | |
| }else{ | |
| headerView.layer.transform = CATransform3DTranslate(headerTransform, 0, max(-40, -offset), 0) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment