动画UIButton Down - Xcode [英] Animate UIButton Down - Xcode

查看:153
本文介绍了动画UIButton Down - Xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何点击通过

-(IBAction)

提前致谢!

推荐答案

在你的 IBAction

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

编辑 - 在帧之间切换

EDIT - To toggle between frames

初始化布尔值点击到某处<或者

initialize boolean clicked to NO somewhere

if (!clicked){

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

     clicked = YES;

} else {


    //animates button 25 pixels left and 25 pixels up. 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];

    clicked = NO;

}

这篇关于动画UIButton Down - Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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