问题
Im using Xcode, and when i tap/drag on my imageView at the bottom of the screen, I want it to be brought up and reveal all of it on screen similiar to the way Spotify does it when you click the banner at the bottom. Any ideas?
回答1:
I recommend using spring animations if you want a nice animation like this:
func buttonTapped(sender: UIButton!) { //or in an IBAction
let duration: NSTimeInterval = 0.75
let damping: CGFloat = 1
let velocity: CGFloat = 0.5
UIView.animateWithDuration(duration, delay: 0.5, usingSpringWithDamping: damping, initialSpringVelocity: velocity, options: .CurveLinear, animations: {
self.myView.center.y = self.view.frame.height/2
}, completion: nil)
}
Sorry for Swift code, if you're not able to translate it then let me know :)
Edit
For Objective-C the code would look something like this:
[UIView animateWithDuration:0.75, delay:0, usingSpringWithDamping:1, initialSpringVelocity:0.5, options:UIViewAnimationOptionsCurveLinear, animations:^{
//Animations
} completion:^(BOOL finished) {
//Completion Block
}];
回答2:
I actually figured it out. I made a button and included this code to trigger the animation:
self.moveX.constant = 200;
[UIView animateWithDuration:2.0f animations:^{
imageView.frame = CGRectMake(0.0f, 200.0f, imageView.frame.size.width,imageView.frame.size.height);
}];
来源:https://stackoverflow.com/questions/30881214/how-to-animate-an-object-vertically-with-touch-like-spotifys-music-player-does