Skip to content

Commit

Permalink
翻页动画加个老虎机特效(先后时差)
Browse files Browse the repository at this point in the history
  • Loading branch information
吕小布 committed Dec 19, 2024
1 parent 18fa2f9 commit 6144f31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion sources/AnimateNSTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AnimateNSTextView: NSTextField {
var animationDuration: Double = 0.2
var animationInterruptType = "smooth"
private var oldTextLayer = CATextLayer()
var i = 0

//转换传入的字符串为CAMediaTimingFunctionName格式
var animationTypeStr: String = "easeOut" {
Expand Down Expand Up @@ -105,16 +106,18 @@ class AnimateNSTextView: NSTextField {
oldLayerAnimation.duration = 0.2
oldLayerAnimation.fillMode = .forwards
oldLayerAnimation.isRemovedOnCompletion = true
oldLayerAnimation.timingFunction = CAMediaTimingFunction(name: .easeOut) // 动画缓动函数
oldTextLayer.add(oldLayerAnimation, forKey: nil)


// 新layer(自有layer)入场动画
let layerAnimation = CABasicAnimation(keyPath: "position.y")
layerAnimation.fromValue = self.frame.origin.y - self.frame.height*CGFloat(isTurning)
layerAnimation.toValue = self.frame.origin.y // 向上移动20个单位
layerAnimation.duration = 0.2
layerAnimation.duration = 0.3 + CGFloat(i) * 0.2
// layerAnimation.fillMode = .forwards
layerAnimation.isRemovedOnCompletion = true
layerAnimation.timingFunction = CAMediaTimingFunction(name: .easeIn) // 动画缓动函数
newTextLayer.add(layerAnimation, forKey: nil)


Expand Down
3 changes: 2 additions & 1 deletion sources/SquirrelPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ private extension SquirrelPanel {
animateNSTextView.animationTypeStr = theme.candidateAnimationType
animateNSTextView.animationDuration = theme.candidateAnimationDuration
animateNSTextView.animationInterruptType = theme.candidateAnimationInterruptType
animateNSTextView.page = page
animateNSTextView.page = page
animateNSTextView.i = i
// animateNSTextView.textContentStorage?.attributedString = lines[i] //如果是NSTextView用这个
animateNSTextView.attributedStringValue = lines[i] //更新视图字符串
// print("更新前lines[i]:[\(lines[i].string)]")
Expand Down

0 comments on commit 6144f31

Please sign in to comment.