I have a uibutton that I animate to scale down. But the hit area doesn't scale down with it and stays at its orignal size.
my code:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
float widthScale = size.width / view.frame.size.width;
float heightScale = size.height / view.frame.size.height;
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(widthScale, heightScale, 1.0)];
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:animation];
animGroup.duration = 0.5;
animGroup.removedOnCompletion = NO;
animGroup.fillMode = kCAFillModeForwards;
[view.layer addAnimation:animGroup forKey:nil];
The button has a image that i set with setImage:forState: I give the button a frame and i put the autoresizeSubviews to YES
This is an old discussion but I just met a similar situation and the question doesn't seem to be really answered...
Layers do not respond to touches directly (touches delegate is only the UIView's controller but not its underlaying CALayer). A possible solution to fix the hit area after animating the layer is to modify the view.frame property (of the backing view) adapting its size and origin explicitly/"manually" to the final (expected) size of the animated layer.
The transformed view.frame will allow again response to touches in a correct area without affecting the animated CALayer shape. In other words, the CALayer object and the frame property of the UIView seem untied.
CAAnimation
scales/etc. the view's underlying layer; the view itself occupies the same bounds. To modify the view itself, try using a UIView
animation block and modifying the view's transform property.
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.