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アルファが常に変化しているため、送信者を受信しません。しかし、私にはそれを解決する方法があります。バックグラウンド ボタンを作成し、送信者を受け取ることができます。次のようにコーディングできます。

    _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 に答える