本文共 1313 字,大约阅读时间需要 4 分钟。
用Easing函数实现碰撞效果
工程中需要的源码请从这里下载:
源码:
//// ViewController.m// EasingView//// Created by YouXianMing on 15/1/17.// Copyright (c) 2015年 YouXianMing. All rights reserved.//#import "ViewController.h"#import "YXEasing.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // 显示的view UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(100, -100, 100, 100)]; showView.backgroundColor = [UIColor clearColor]; showView.layer.borderColor = [UIColor redColor].CGColor; showView.layer.borderWidth = 4.f; showView.layer.cornerRadius = 50.f; [self.view addSubview:showView]; // 关键帧动画 CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; // 设置值 [animation setValues:[YXEasing calculateFrameFromPoint:showView.center toPoint:CGPointMake(showView.center.x, showView.center.y + 565) func:BounceEaseOut frameCount:100]]; // 设置持续时间 animation.duration = 1.f; // 执行动画效果 showView.center = CGPointMake(showView.center.x, showView.center.y + 565); [showView.layer addAnimation:animation forKey:nil];}@end
转载地址:http://vnczl.baihongyu.com/