gpt4 book ai didi

ios - 如何给 UITextView 或 UILabel 添加滑动解锁效果?

转载 作者:可可西里 更新时间:2023-11-01 03:06:55 24 4
gpt4 key购买 nike

我有一个大文本,想添加一种类似于幻灯片的效果来解锁最新的 iOS 之一,并且会从上到下移动,文本从下到上滑动。

最佳答案

Update with swift shimmering label, view etc...

import UIKit
import QuartzCore

class ViewController: UIViewController {

@IBOutlet var testLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
self.testLabel.startShimmering()
}
}

extension UIView {
func startShimmering() {
// let light = UIColor.init(white: 0, alpha: 0.1).cgColor
let light = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
let dark = UIColor.black.cgColor

let gradient: CAGradientLayer = CAGradientLayer()
gradient.colors = [dark, light, dark]
gradient.frame = CGRect(x: -self.bounds.size.width, y: 0, width: 3*self.bounds.size.width, height: self.bounds.size.height)
gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
gradient.endPoint = CGPoint(x: 1.0, y: 0.525)
gradient.locations = [0.4, 0.5, 0.6]
self.layer.mask = gradient

let animation: CABasicAnimation = CABasicAnimation(keyPath: "locations")
animation.fromValue = [0.0, 0.1, 0.2]
animation.toValue = [0.8, 0.9, 1.0]

animation.duration = 1.5
animation.repeatCount = HUGE
gradient.add(animation, forKey: "shimmer")


}

func stopShimmering() {
self.layer.mask = nil
}

}

关于ios - 如何给 UITextView 或 UILabel 添加滑动解锁效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com