左 - 右 - 左子视图动画 [英] Animating subviews left-right-left

查看:156
本文介绍了左 - 右 - 左子视图动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个视图像QuickActionBar在Android中,当其在左上角有一个按钮,点击打开简单,但是它的子视图看起来好像他们是从右边过来,打在左边的墙上,反弹回来,然后进驻。
观点出现,但我无法动画子视图。

I want to create a view like the QuickActionBar in Android , which when clicked on a button in top left corner opens simply , but it subviews appears as if they are coming from Right , hit on the left wall , and rebounded back , and then stationed . view is appearing , but i am unable to animate the subviews..

推荐答案

CAKeyframeAnimation查找适合您的问题。我以前写了这个动画功能一个标签在整个屏幕上滑动。我稍微更新xValues​​你的目的,但最有可能你会和他们一起玩。碰壁后,也有可能希望使用scale.y值玩,你可以很容易地集成到关键帧动画。

CAKeyframeAnimation looks right for your problem. I have written this animation function before for a label sliding across screen. I updated xValues slightly for your purposes but most probably you will have to play with them. Also after hitting the wall you might want to play with scale.y value you can easily integrate that into keyframe animation.

+ (void) slideAcrossScreen:(UIView *) view Duration:(CGFloat) duration FromLeft:(BOOL) fromLeft
{
    //This is to make it work with both left-right-left and right-left-right anims.
    CGFloat slideLength = fromLeft ? -view.frame.origin.x : [[UIScreen mainScreen] bounds].size.width - (view.frame.origin.x + view.frame.size.width);

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];

    NSArray *xValues =
              @[[NSNumber numberWithFloat:view.bounds.origin.x],
                [NSNumber numberWithFloat:view.bounds.origin.x + 10 * slideLength / 10],
                [NSNumber numberWithFloat:view.bounds.origin.x + 10 * slideLength / 10],
                [NSNumber numberWithFloat:view.bounds.origin.x + 9 * slideLength / 10]];

    [anim setValues:xValues];

    NSArray *timeFrames = 
              @[[NSNumber numberWithFloat:0.0],
                [NSNumber numberWithFloat:0.85],
                [NSNumber numberWithFloat:0.9],
                [NSNumber numberWithFloat:1.0]];

    [anim setKeyTimes:timeFrames];
    [anim setDuration:duration];
    [anim setFillMode:kCAFillModeForwards];
    [anim setRemovedOnCompletion:FALSE];

    [view.layer addAnimation:anim forKey:@"slide"];
}

这篇关于左 - 右 - 左子视图动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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