objective-c - UIView动画改变按钮的大小

标签 objective-c ios uibutton beginanimations

我开始尝试从应用商店重新创建购买按钮,该按钮需要 2 阶段点击才能购买。我为按钮的展开设置动画。到目前为止我有这个

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];

sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);

[UIView commitAnimations];

这只会导致按钮变大,它根本没有动画。我是不是做错了什么,或者其他人是否实现了这种类型的按钮行为?

编辑:

- (IBAction) buyButtonAction: (UIButton *) sender {

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

sender.clipsToBounds = NO;

sender.frame = CGRectMake( CGRectGetMinX( sender.frame) - 30, CGRectGetMinY(sender.frame), 200, 37);
[sender setTitle:@"Touched Touched Touched" forState:UIControlStateNormal];


[UIView commitAnimations];
}

最佳答案

您的目标是不支持 Blocks 的 iOS 吗?

我已经使用以下令人作呕的简单代码实现了“触摸时的按钮动画”。

[UIView animateWithDuration:0.5 animations:^{
    self.navigationItem.rightBarButtonItem.title = @"Quoting...";
}];

或者,如果您不支持 block (如果您走这条路,它还包括被注释掉的 block ),这段代码似乎也可以为触摸按钮设置动画:

-(IBAction) clicked:(UIButton*)sender{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    //[UIView animateWithDuration:2.5 animations:^{

    sender.autoresizesSubviews = NO;
    sender.clipsToBounds = NO;
    sender.frame = CGRectMake(63,326,200,37);

    //sender.frame = CGRectMake( CGRectGetMinX( self.theButton.frame) - 100, CGRectGetMinY(self.theButton.frame), 300, 40);
    //[sender setTitle:@"Touched Touched Touched" forState:UIControlStateNormal];
//}];

关于objective-c - UIView动画改变按钮的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939866/

相关文章:

ios - 从 tableView :cellForRowAtIndexPath: 内的 block 调用时,cellForRowAtIndexPath 始终为零

ios - UIView animateWithDuration 返回原始状态

ios 将通知推送到特定的 View Controller

ios - 当我在 Xcode 9 中编译我的应用程序时出现 BoringSSL 错误

iOS - UIPageControl 上的 UIButton 不工作

iOS 如何以编程方式在单个方法中插入两个 UIButton?

objective-c - 节省 boolean 值的问题

objective-c - 如何创建包含静态库的 pod?

sql-server - Objective-C:数据库支持

ios - 为什么我的 UIButton 的背景层会出现动画,我该如何停止它?