iphone - UIView.frame 的核心动画

标签 iphone core-animation

我正在尝试制作一个移动两个 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/

相关文章:

ios - 设置 IBOutlet 的属性

iphone - 使用 NSURLRequest 将数据发布到服务器时出现问题

iOS - 动画和性能?

ios - 如何同步几个不同图层的CAKeyframeAnimation动画?

ios - 如何在 UIView 的 layerClass 实例上使用 CIFilter?

iphone - 我如何知道 CATiledLayer 何时渲染了所有可见图 block ?

iphone - Xcode上的怪异编译错误

iOS - 在更新到新版本时保留旧的 sqlite 数据库

ios - 在 ios7 xcode 中设置相机焦点。打开简历

ios - 如何将 Sprite 扭曲为梯形?