发光效果的视图禁用按钮

时间:2012-11-17 20:47:54

标签: iphone objective-c ios xcode

我有uiscrollview,里面有一些按钮。我想让一个特定的按钮发光。

我用以下代码制作了按钮的发光脉动效果:

(UIView中的按钮)

- (IBAction)selectChampionAction:(id)sender{
    if ( self.timer ) {
            // Stop timer
            [self.timer invalidate];
            self.timer = nil;
            // Workaround: we have to return the layer's delegate property to what it was
            // Otherwise, we will encounter an unexpected result
            self.viewForGlowing.layer.delegate = self.viewForGlowing;
        } else {
            // Woraround: UIView's layer property does not support animation by default
            // assigning nil to layer's delegate property enables the animation somehow.
            self.viewForGlowing.layer.delegate = nil;
            // Start timer
            self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerExpired:) userInfo:nil repeats:YES];
            [self.timer fire];
        }
}


 - (void) timerExpired:(NSTimer *) timer
{
    if ( self.viewForGlowing.layer.shadowRadius == 20 ) {
        // Increase

        [CATransaction begin];
        [CATransaction setValue:[NSNumber numberWithFloat:1.0f] forKey:kCATransactionAnimationDuration];

        self.viewForGlowing.layer.shadowRadius = 30; 
        self.viewForGlowing.layer.shadowOpacity = 1;
        [CATransaction commit];

    } else {
        // Decrease

        [CATransaction begin];
        [CATransaction setValue:[NSNumber numberWithFloat:1.0f] forKey:kCATransactionAnimationDuration];
        self.viewForGlowing.layer.shadowRadius = 20;
        self.viewForGlowing.layer.shadowOpacity = 0.7;
        [CATransaction commit];
    }
}

但是当我按下其他按钮时,发光按钮会停止响应。

我认为这是因为这行代码

  

self.viewForGlowing.layer.delegate = nil;


我的问题:

  • 还有其他方法让UIButton发光吗?
  • 按下其他按钮后如何进行按钮响应?

0 个答案:

没有答案