cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/QMUIComponents/QMUIAnimation/QMUIDisplayLinkAnimation.h

141 lines
7.0 KiB
C
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// QMUIDisplayLinkAnimation.h
// WeRead
//
// Created by zhoonchen on 2018/9/3.
//
#import <UIKit/UIKit.h>
#import "QMUIAnimationHelper.h"
#define SpringAnimationDefaultDuration 0.5
/*
* CADisplayLink CAAnimation
* 1
* 2使 CADisplayLink CALayer UI
* 3 CAAnimation app 退
* 4线线
* @warning: stop dealloc `QMUIDisplayLinkAnimation` CADisplayLink
*/
@interface QMUIDisplayLinkAnimation : NSObject
@property(nonatomic, strong, readonly) CADisplayLink *displayLink;
@property(nonatomic, strong) id fromValue;
@property(nonatomic, strong) id toValue;
/// 动画时间
@property(nonatomic, assign) NSTimeInterval duration;
/// 动画曲线
@property(nonatomic, assign) QMUIAnimationEasings easing;
/// 是否需要重复如果设置为YES那么会无限重复动画默认NO
/// TODO: 目前功能上不支持小数点的循环次数,例如 0.5 1.5
@property(nonatomic, assign) BOOL repeat;
/// 延迟开始动画
@property(nonatomic, assign) NSTimeInterval beginTime;
/// 只有设置了repeat之后这个值才有用
@property(nonatomic, assign) float repeatCount;
/// 只有设置了repeat之后这个值才有用。如果YES则往前做动画之后自动往后做动画默认NO
@property(nonatomic, assign) BOOL autoreverses;
/// 做动画的block适用于只有一个属性需要做动画curValue是经过计算后当前帧的值
@property(nonatomic, copy) void (^animation)(id curValue);
/// 做动画的block适用于多个属性做动画需要在block里面自己计算当前帧的所有属性的值
@property(nonatomic, copy) void (^animations)(QMUIDisplayLinkAnimation *animation, CGFloat curTime);
- (instancetype)initWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
fromValue:(id)fromValue
toValue:(id)toValue
animation:(void (^)(id curValue))animation;
- (instancetype)initWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
animations:(void (^)(QMUIDisplayLinkAnimation *animation, CGFloat curTime))animations;
/// 开始动画,无论是第一次做动画或者暂停之后再重新做动画,都调用这个方法
- (void)startAnimation;
/// 停止动画CADisplayLink 对象会被移出
- (void)stopAnimation;
/// 即将开始做动画
@property(nonatomic, copy) void (^willStartAnimation)(void);
/// 动画结束
@property(nonatomic, copy) void (^didStopAnimation)(void);
@end
@interface QMUIDisplayLinkAnimation (ConvenienceClassMethod)
/*
* QMUIDisplayLinkAnimation 便
* `createdBlock` animation animation
* `didStopBlock`
* @warning: block 使
*/
+ (instancetype)springAnimateWithFromValue:(id)fromValue
toValue:(id)toValue
animation:(void (^)(id curValue))animation
createdBlock:(void (^)(QMUIDisplayLinkAnimation *animation))createdBlock;
+ (instancetype)animateWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
fromValue:(id)fromValue
toValue:(id)toValue
animation:(void (^)(id curValue))animation;
+ (instancetype)animateWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
fromValue:(id)fromValue
toValue:(id)toValue
animation:(void (^)(id curValue))animation
createdBlock:(void (^)(QMUIDisplayLinkAnimation *animation))createdBlock;
+ (instancetype)animateWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
fromValue:(id)fromValue
toValue:(id)toValue
animation:(void (^)(id curValue))animation
createdBlock:(void (^)(QMUIDisplayLinkAnimation *animation))createdBlock
didStopBlock:(void (^)(QMUIDisplayLinkAnimation *animation))didStopBlock;
+ (instancetype)springAnimateWithAnimations:(void (^)(QMUIDisplayLinkAnimation *animation, CGFloat curTime))animations
createdBlock:(void (^)(QMUIDisplayLinkAnimation *animation))createdBlock;
+ (instancetype)animateWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
animations:(void (^)(QMUIDisplayLinkAnimation *animation, CGFloat curTime))animations;
+ (instancetype)animateWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
animations:(void (^)(QMUIDisplayLinkAnimation *animation, CGFloat curTime))animations
createdBlock:(void (^)(QMUIDisplayLinkAnimation *animation))createdBlock;
+ (instancetype)animateWithDuration:(NSTimeInterval)duration
easing:(QMUIAnimationEasings)easing
animations:(void (^)(QMUIDisplayLinkAnimation *animation, CGFloat curTime))animations
createdBlock:(void (^)(QMUIDisplayLinkAnimation *animation))createdBlock
didStopBlock:(void (^)(QMUIDisplayLinkAnimation *animation))didStopBlock;
@end