Last active
September 15, 2015 02:33
-
-
Save demonar/1882acdbbe3e3e215998 to your computer and use it in GitHub Desktop.
This file contains 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
import UIKit | |
extension UIView { | |
func scrollToY(y: CGFloat) { | |
scrollToY(y, velocity: 0.25) | |
} | |
func scrollToView(view: UIView) { | |
scrollToView(view, velocity: 0.25) | |
} | |
func scrollElement(view: UIView, toPoint y: CGFloat) { | |
scrollElement(view, toPoint: y, velocity: 0.25) | |
} | |
func scrollToY(y: CGFloat, velocity: NSTimeInterval) { | |
UIView.animateWithDuration(velocity, animations: { () -> Void in | |
self.transform = CGAffineTransformMakeTranslation(0, y) | |
}) | |
} | |
func scrollToView(view: UIView, velocity: NSTimeInterval) { | |
let theFrame = view.frame | |
var y : CGFloat = theFrame.origin.y - 15 | |
y -= (y/1.7) | |
self.scrollToY(-y, velocity: velocity) | |
} | |
func scrollElement(view: UIView, toPoint y: CGFloat, velocity: NSTimeInterval) { | |
let originY = view.frame.origin.y | |
let diff = y - originY | |
if (diff < 0) { | |
self.scrollToY(diff, velocity: velocity) | |
} | |
else { | |
self.scrollToY(0, velocity: velocity) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment