UIView.frame的核心动画 [英] Core Animation for UIView.frame

查看:146
本文介绍了UIView.frame的核心动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的动画来移动两个视图的框架。基本上隐藏广告,直到广告被加载,然后从底部开始向上移动框架,以及从底部开始的视图,然后在广告将其向上推动时也向上移动。起点和终点位置正确,但我看不到它有动画效果。这样对吗?

I'm trying to do a simple animation of moving the frame of two views. Basically hiding the Ad until it is loaded, and then move the frame up from the bottom, along with the view that starts at the bottom, and then will move up also when the Ad pushes it up. The start and end positions are correct, but I don't see it being animated. Is this correct? Thanks.

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的内置动画系统就足够了。

For something as simple as this, you don’t really need to use Core Animation directly—UIView’s built-in animation system should suffice.

[UIView animateWithDuration:1.0 animations:^{
    self.adBanner.frame = adFrame;
    self.ButtonView.frame = buttonViewFrame;
}];

或者,如果您的目标是4.0之前的iOS,

or, if you’re targeting pre-4.0 iOS,

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
    self.adBanner.frame = adFrame;
    self.ButtonView.frame = buttonViewFrame;
[UIView commitAnimations];

这篇关于UIView.frame的核心动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆