我正在尝试从下到上逐渐隐藏一个UIImageView
。
在Objective-C中,最好和最有效的方法是什么?我正在研究CABasicAnimation
类和动画类。
发布于 2014-07-30 16:05:09
如果您想深入了解CoreAnimation,我认为您可以使用以下内容:
CABasicAnimation *animationA=[CABasicAnimation animation];
animationA.keyPath=@"position.y";
animationA.fromValue=@0;
animationA.toValue=@250;
animationA.duration=3;
animationA.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[yourTestView.layer addAnimation:animationA forKey:@"basic"];
yourTestView.layer.position=CGPointMake(250, 50);
或者,如果只想支持IOS7,可以尝试学习UIAttachmentBehavior和UIDynamicItemBehavior以实现更具交互性的动画。
发布于 2014-07-30 15:40:04
所有像这样的动画都使用核心动画,并且可以简单地使用基于块的动画来完成。
为此,您将执行如下操作:
[UIView animateWithDuration:3
animations:^{
imageView.frame = CGRectMake(//the end frame of the image view
}];
然后,这将在给定的持续时间内以动画形式显示更改。(在本例中为3秒)。
你可以在UIView
的文档中找到其他版本,它们为你提供了更多的选择,比如更改动画曲线或在完成时运行一些代码等。
笔记
这假设您没有使用自动布局。如果您使用的是自动布局,那么方法是完全相同的,但是您需要更改约束,然后在animations
块中运行[view layoutIfNeeded];
。
https://stackoverflow.com/questions/25031141
复制相似问题