我手边有一个奇怪的问题。我有UITextField。点击按钮时,此TextField的宽度已调整大小。为此,我首先做了以下事情:
CGRect newbounds = originalBounds;
newbounds.size.width = newbounds.size.width/2;
[UIView beginAnimations:nil context:nil];
self.textField2.bounds = newbounds;
[UIView commitAnimations];
足够简单且有效。现在我继续前进并尝试对动画施加更多控制。为此,我使用以下内容进入CABasicAnimation的下一级:
CGRect newbounds = originalBounds;
newbounds.size.width = newbounds.size.width/2;
CABasicAnimation *animShrink = [CABasicAnimation animation];
animShrink.keyPath = @"bounds";
animShrink.toValue = [NSValue valueWithCGRect:newbounds];
animShrink.duration = 0.5;
animShrink.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animShrink.delegate = self;
[self.textField2.layer addAnimation:animShrink forKey:@"shrink"];
这就是当我在动画期间遇到剪辑问题时,可以看到:http://coldstorage.macbonsai.com/public/cabasic_animation_clipping.png(因为我“需要至少10个声望来发布图像”,如Stackoverflow所示)。
所以我尝试了以下版本的动画:
CGRect newbounds = originalBounds;
newbounds.size.width = newbounds.size.width/2;
CABasicAnimation *animShrink = [CABasicAnimation animation];
animShrink.keyPath = @"bounds.size.width";
animShrink.fromValue = [NSNumber numberWithFloat:originalBounds.size.width];
animShrink.toValue = [NSNumber numberWithFloat:newbounds.size.width];
animShrink.duration = 0.5;
animShrink.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animShrink.delegate = self;
[self.textField2.layer addAnimation:animShrink forKey:@"shrink"];
仍遇到同样的问题。此时,我从UITextField中删除了所有约束,并尝试了两个CABasicAnimation版本。同样的问题。此时我不知道还能做什么。任何帮助将不胜感激。
非常感谢提前。
答案 0 :(得分:0)
如果您将按钮的样式更改为UITextBorderStyleNone,则不会对其进行剪裁。
我的猜测是,当样式是UITextBorderStyleRoundedRect时,Apple可能只是将一个UIImageView添加到按钮中,并使用" round rect"图片,所以当您为按钮的图层设置动画时,其子视图不会同时显示动画,因为在iOS中您必须显式设置所有子图层的动画。