1

我想要一个闪烁的按钮,然后我像这样编码我像这样初始化按钮:

_btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
[_btn addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
[_btn setBackgroundImage:[UIImage imageNamed:@"img2.jpg"] forState:UIControlStateNormal];

我像这样对动画进行编码:

[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
    _btn.alpha = 0.2;
} completion:nil];

按钮模糊但无法选择,无法接收发件人。有谁知道为什么收不到发件人?

4

2 回答 2

1

试试这个

[UIView animateWithDuration:1 delay:0 options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
    _btn.alpha = 0.2;
} completion:nil];

我已将其作为选项插入到上面的代码中

UIViewAnimationOptionAllowUserInteraction
于 2013-01-10T09:04:28.450 回答
1

我没有t know why it can收到发件人,可能是因为 alpha 一直在变化。但我有办法解决它。你可以创建一个背景按钮,它可以接收发件人,你可以这样编码:

    _btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    _btn.userInteractionEnabled = NO;
    [_btn setBackgroundImage:[UIImage imageNamed:@"img2.jpg"] forState:UIControlStateNormal];


    _btn1 = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
    [_btn1 addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
    [_btn1 setBackgroundColor:[UIColor clearColor]];
    [_btn1 addSubView : _btn];

然后像你的代码一样设置动画

[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse animations:^{
    _btn.alpha = 0.2;
} completion:nil];

button1 将接收发件人

于 2013-01-10T09:13:17.353 回答