
例如我有一个视图MyVIEw,它有一个属性值,每当设置值时我调用setNeedsdisplay并且视图知道要绘制的内容.
为了动画这我使用CAdisplaylink,我希望视图在值之间“变形”.我只是通过插入动画的开始和结束值来实现这一点:
– (CGfloat)interpolatedValue:(CGfloat)sourceValue withValue:(CGfloat)targetValue forProgress:(CGfloat)进展;
现在获得一个线性进展很容易并得到一个“特定曲线”(好),但我希望能够利用camediatimingFunction来做到这一点(或者其他一些预先存在的逻辑 – 我不想再次重新发明轮子’: )
解决方法 有这个令人敬畏的要点RSTiming,在你的情况下可能会很方便.您可以使用标准camediatimingFunction定义定时功能,甚至可以使用2个控制点定义定制功能来定义贝塞尔曲线. 如果我得到你的设置,你可能会有这样的事情:
视图控制器
#import "VIEwController.h"#import "AnimatedVIEw.h"#include <stdlib.h>@interface VIEwController ()@property (nonatomic,strong) CAdisplaylink *displaylink;@property (weak,nonatomic) IBOutlet AnimatedVIEw *vIEwToAnimate;@end@implementation VIEwController- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; self.displaylink = [CAdisplaylink displaylinkWithTarget:self selector:@selector(updateFrame)]; [self.displaylink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];}- (voID)updateFrame { [self.vIEwToAnimate updateAnimation];}- (IBAction)updateAnimationTapped:(ID)sender { self.vIEwToAnimate.value = arc4random_uniform(101) / 100.0; NSLog(@"Next animation value: %f",self.vIEwToAnimate.value);}@end AnimatedVIEw
#import "AnimatedVIEw.h"#import "RSTimingFunction.h"@interface AnimatedVIEw(){ CGfloat _lastValue; CGfloat _progressstep; CGfloat _currentProgress;}@property (nonatomic,strong) RSTimingFunction *animationProgress;@end@implementation AnimatedVIEw- (instancetype)initWithCoder:(NSCoder *)aDecoder{ if ((self = [super initWithCoder:aDecoder])) { _progressstep = 0.01; // defines animation speed _currentProgress = 1.0; self.animationProgress = [RSTimingFunction timingFunctionWithname:kRSTimingFunctionEaseInEaSEOut]; } return self;}- (voID)setValue:(CGfloat)value { if (_value != value) { _lastValue = _value; _value = value; _currentProgress = 0.0; }}- (voID)updateAnimation{ if (_currentProgress > 1.0) return; _currentProgress += _progressstep; CGfloat currentAnimationValue = _lastValue + (_value - _lastValue) * [self.animationProgress valueForX:_currentProgress]; self.Alpha = currentAnimationValue; // as an example animate Alpha}@end 如上所述,您甚至可以设置2个控制点来创建以三次贝塞尔曲线为模型的定时函数.
self.animationProgress = [RSTimingFunction timingFunctionWithControlPoint1:CGPointMake(0.6,0.6) controlPoint2:CGPointMake(0.1,0.8)];
这将产生以下时间动画(使用CAMediaTimingFunction playground制作)
总结以上是内存溢出为你收集整理的ios – 使用CADisplayLink’结合’与CAMediaTimingFunction动画UIView. (获得任意曲线)全部内容,希望文章能够帮你解决ios – 使用CADisplayLink’结合’与CAMediaTimingFunction动画UIView. (获得任意曲线)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)