How to animate an object vertically with touch like Spotify's music player does when tapping the song,

≡放荡痞女 提交于 2019-12-12 02:16:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!