我正在尝试制作一个移动两个 View 的框架的简单动画。基本上隐藏广告直到加载,然后将框架从底部向上移动,以及从底部开始的 View ,然后当广告将其向上推时也会向上移动。开始和结束位置是正确的,但我没有看到它是动画的。它是否正确?谢谢。
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
animation.duration = 1.0;
CGRect adFrame = CGRectMake(self.adBanner.frame.origin.x, self.adBanner.frame.origin.y - self.adBanner.frame.size.height, self.adBanner.frame.size.width, self.adBanner.frame.size.height);
self.adBanner.frame = adFrame;
[self.adBanner.layer addAnimation:animation forKey:@"frame"];
CGRect buttonViewFrame = CGRectMake(self.ButtonView.frame.origin.x, self.adBanner.frame.origin.y - self.adBanner.frame.size.height, self.ButtonView.frame.size.width, self.ButtonView.frame.size.height);
self.ButtonView.frame = buttonViewFrame;
[self.ButtonView.layer addAnimation:animation forKey:@"frame"];
最佳答案
对于这样简单的事情,你并不需要直接使用 Core Animation——UIView 的内置动画系统就足够了。
[UIView animateWithDuration:1.0 animations:^{
self.adBanner.frame = adFrame;
self.ButtonView.frame = buttonViewFrame;
}];
或者,如果您的目标是 4.0 之前的 iOS,
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
self.adBanner.frame = adFrame;
self.ButtonView.frame = buttonViewFrame;
[UIView commitAnimations];
关于iphone - UIView.frame 的核心动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6728434/