UIButton AppStore购买按钮动画 [英] UIButton AppStore buy button animation

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

问题描述

您是否有AppStore价格的UIButton动画示例代码 - >购买按钮。我尝试了很多,但它不能很好地与CAAnimationGroup(缩放+转换)一起使用,并且它只能在UIView beginAnimations中将其设置为新的帧大小。动画首先设置新的宽度(立即)然后设置新的原点..所以它不是正确的效果...

Do you have a sample code for the UIButton animation of the AppStore Price -> to Buy button. I tried a lot, but it doesn't work well with CAAnimationGroup (scale+translation) and it doesn't work with just setting it to the new frame-size in a UIView beginAnimations. The animation first sets the new width(immediatelly) and then the new origin .. so it is not the right effect ...

谢谢!

推荐答案

您是否在核心动画块中进行了更改?

Are you making your changes inside the Core Animation block?

我创建了一个简单的基于视图的iPhone应用程序来测试这个。该视图有两个圆角矩形UIButton对象:

I created a simple view-based iPhone application to test this. The view has two rounded rect UIButton objects:


  1. 第一个按钮位于右上角,宽度为62(高度为35) )和初始标题0.99美元。它连接到视图控制器中的按钮插座和动画动作。这是点击它时将被设置动画的按钮。

  1. The first button is in the upper right corner with width 62 (and height 35) and initial title "$0.99". It is connected to the "button" outlet and "animate" action in the view controller. This is the button that will be animated when it is tapped.

第二个按钮位于屏幕底部,标题为重置并连接到我的视图控制器中的重置操作。

The second button is at the bottom of the screen with title "Reset" and is connected to the "reset" action in my view controller.

以下是视图控制器代码:

Here is the view controller code:

UIButtonAnimationTestViewController.h:

#import <UIKit/UIKit.h>

@interface UIButtonAnimationTestViewController : UIViewController {
    IBOutlet UIButton *button;
    CGRect originalFrame;
}

- (IBAction)animate;
- (IBAction)reset;

@end

UIButtonAnimationTestViewController.m:

#import "UIButtonAnimationTestViewController.h"

@implementation UIButtonAnimationTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    originalFrame = button.frame;
}

- (IBAction)animate {
    CGRect frame = button.frame;
    frame.origin.x -= 30;
    frame.size.width += 30;

    [UIView beginAnimations:@"button" context:nil];
    button.frame = frame;
    [button setTitle:@"" forState:UIControlStateNormal];
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [button setTitle:@"BUY NOW" forState:UIControlStateNormal];
}

- (IBAction)reset {
    button.frame = originalFrame;
    [button setTitle:@"$0.99" forState:UIControlStateNormal];
}

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

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