简体   繁体   中英

Animating custom UIButton in UITableViewCell

I'm having trouble getting an animation to display when a UIButton is tapped in a custom UITableViewCell. The IBAction is being called correctly. I want a blue shadow to appear around the UIButton . Here's the code:

-(IBAction)handleButtonTap:(UIButton*)sender {
[self animateBlueShadowAroundView:sender];
}

-(void)animateBlueShadowAroundView:(UIView*)view {
[UIView animateWithDuration:1.0 animations:^{ [self configureBlueShadow:view]; } ];
}

-(void)configureBlueShadow:(UIView*)view {
view.layer.shadowColor = [UIColor blueColor].CGColor;
view.layer.shadowRadius = 7.0;
view.layer.shadowOpacity = 1.0;
}

I also tried doing the animation in cellForRowAtIndexPath and reloading the row that needed the animation, but that didn't work either. I would prefer for the animation to happen as part of the above IBAction handleButtonTap: .

Nothing happens. I don't see any animation at all, but I am confirming the above IBAction is being called.

What am I missing?

Oops. I should have read more about CALayers and Core Animation.

UIView 's animation methods (as I used above) can only animate certain properties. To animate properties of the CALayer you must use Core Animation classes and methods, not UIView 's.

Here's a great reference I found: apeth.com/iOSBook

From the reference:

Animation is ultimately layer animation. However, for a limited range of attributes, you can animate a UIView directly: these are its alpha,backgroundColor, bounds, center, frame, and transform.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM