在Swift中动画UIButton

Cas*_*per 3 animation uibutton ios jquery-animate swift

我正在进行我的第一场比赛Swift,我想知道如何在用户按下按钮时为Z位置(或缩小和高档)按钮设置动画.

我虽然找到了答案,但我找到的所有内容都是写的Objective-C,因为我刚开始编码,所以我很难翻译Obj-CSwift.

这是我发现的:

UIButton *button = (UIButton*)sender;

//animates button 25 pixels right and 25 pixels down. Customize
CGRect newFrame = CGRectMake(button.frame.origin.x + 25, button.frame.origin.y + 25, button.frame.size.width, button.frame.size.height);

[UIView animateWithDuration:0.3f
                      delay:0.0f
                    options: UIViewAnimationOptionCurveLinear
                 animations:^{
                     [button setFrame:newFrame];
                 }
                 completion:nil];
Run Code Online (Sandbox Code Playgroud)

rak*_*hbs 9

试试这个

@IBAction func clicked(sender: AnyObject) {

    button = sender as UIButton

    UIView.animateWithDuration(1.0, animations:{
        self.button.frame = CGRectMake(self.button.frame.origin.x + 25, self.button.frame.origin.y + 25, self.button.frame.size.width, self.button.frame.size.height)
    })

}
Run Code Online (Sandbox Code Playgroud)

了解更多信息,请阅读这篇文章http://mathewsanders.com/prototyping-iOS-iPhone-iPad-animations-in-swift/