如何在点按歌曲时像Spotify的音乐播放器一样通过触摸垂直为对象设置动画, [英] How to animate an object vertically with touch like Spotify's music player does when tapping the song,

查看:93
本文介绍了如何在点按歌曲时像Spotify的音乐播放器一样通过触摸垂直为对象设置动画,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode,当我点击/拖动屏幕底部的imageView时,我希望它被调出并在屏幕上显示所有内容,与单击Spotify时的Spotify方式相似底部。有任何想法吗?

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?

推荐答案

如果您想要这样的精美动画,我建议使用spring动画:

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)
}

抱歉,如果您无法翻译Swift代码,请告诉我:)

Sorry for Swift code, if you're not able to translate it then let me know :)

编辑

对于Objective-C,代码应如下所示:

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
}];

这篇关于如何在点按歌曲时像Spotify的音乐播放器一样通过触摸垂直为对象设置动画,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆