ios - UIButton 动画 ontarget self

标签 ios objective-c uibutton

我正在开发一个带有两个 UIButton 的应用程序,它们在按下时必须改变大小和颜色。我的代码是:

    UIButton *Answer1Button = [UIButton buttonWithType:UIButtonTypeCustom];

    UIButton *Answer2Button = [UIButton buttonWithType:UIButtonTypeCustom];

    [Answer1Button addTarget:self action:@selector(Answer1Action) forControlEvents:UIControlEventTouchUpInside];


    [Answer2Button addTarget:self action:@selector(Answer2Action) forControlEvents:UIControlEventTouchUpInside];

    [Answer1Button setBackgroundColor:[UIColor redColor]];
    [Answer2Button setBackgroundColor:[UIColor yellowColor]];
    Answer1Button.frame = CGRectMake(0, 0, 320, 45);
    Answer2Button.frame = CGRectMake(0, 50, 320, 45);

以及我为它创建的函数:

-(void)Answer1Action{


[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
self.backgroundColor = [UIColor greenColor];

self.alpha = 0.5;

[UIButton commitAnimations];    
}

我现在遇到的问题是,当我按下 UIButton 时,函数被调用,但 self.alpha 影响按钮所在的整个 UIView。

我仍然是 Objective-C 的新手,所以我认为这可能是我忘记的简单内容。

最佳答案

[Answer1Button setBackgroundColor:[UIColor greenColor]];
[Answer1Button setAlpha:0.5];

//Include QuartzCore framework and import it to your viewController.h,and write the below line along with the above code to change the size and to do many animations.

Answer1Button.layer.affineTransform=CGAffineTransformScale(Answer1Button.transform, 1.2, 1.2);

关于ios - UIButton 动画 ontarget self,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19949659/

相关文章:

ios - objc_msgSend EXC_BAD_ACCESS 使用关闭按钮时

objective-c - 按对象值对NSMutableArray排序

ios - 使用 UITableView 创建下拉菜单

android - 开发服务器以托管智能手机应用程序内容

ios - 使用 iOS 加速度计确定重大移动的好方法是什么?

ios - 当我从纵向模式更改为横向模式时,按钮背景图像消失

ios - 根据 coredata 中的属性名称获取唯一对象

objective-c - Obj-C中如何处理字符编码?

iphone - 在 iOS 5 中检测用户对 MKMapView 的触摸

ios - 设置数据库中索引值的数组