いくつuiscrollview
かのボタンがあります。1つの特定のボタンを光らせたいです。
次のコードでボタンの光る脈動効果を作りました:
(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を光らせる他のアプローチはありますか?
- 他のボタンを押した後にボタンを応答させる方法は?