创建“隐形墨水”在 Swift 或 SwiftUI 中的效果
我正在尝试创建一个“隐形墨水”动画视图,就像 消息 中存在的动画视图一样 应用程序。
正如我所看到的,Apple 有一个名为 CKInvisibleInkImageEffectView 的框架,但它是私有的。
我能够使用私有框架获得类似的结果,但我想从头开始或使用开源框架创建它。
使用私有 API 的结果:
class ViewController: UIViewController {
@IBOutlet private weak var contentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
updateUI()
}
private func updateUI() {
if let invisibleInk = getInvisibleInkEffectView() {
invisibleInk.frame = CGRect(origin: .zero, size: contentView.bounds.size)
contentView.addSubview(invisibleInk)
invisibleInk.layer.cornerRadius = invisibleInk.bounds.height / 2
invisibleInk.backgroundColor = .systemBrown
invisibleInk.layer.masksToBounds = true
}
}
private func getInvisibleInkEffectView() -> UIView? {
dlopen("/System/Library/PrivateFrameworks/ChatKit.framework/ChatKit", RTLD_NOW)
let invisibleInkView = NSClassFromString("CKInvisibleInkImageEffectView") as? UIView.Type
let view = invisibleInkView?.init()
return view
}
}
消息应用中的效果我想实现:
任何人都知道是否有任何开源框架或如何创建它Swift 还是 SwiftUI?
谢谢
I'm trying to create an "Invisible Ink" animated view, like the one existed in Messages app.
As I could see, Apple have a framework for it called CKInvisibleInkImageEffectView
but it's private.
I was able to get a similar result using the private one, but I'd like to create it from scratch or using an open source framework.
Result using the private API:
class ViewController: UIViewController {
@IBOutlet private weak var contentView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
updateUI()
}
private func updateUI() {
if let invisibleInk = getInvisibleInkEffectView() {
invisibleInk.frame = CGRect(origin: .zero, size: contentView.bounds.size)
contentView.addSubview(invisibleInk)
invisibleInk.layer.cornerRadius = invisibleInk.bounds.height / 2
invisibleInk.backgroundColor = .systemBrown
invisibleInk.layer.masksToBounds = true
}
}
private func getInvisibleInkEffectView() -> UIView? {
dlopen("/System/Library/PrivateFrameworks/ChatKit.framework/ChatKit", RTLD_NOW)
let invisibleInkView = NSClassFromString("CKInvisibleInkImageEffectView") as? UIView.Type
let view = invisibleInkView?.init()
return view
}
}
Effect in Message App I would like to implement:
Anyone knows if there is any open source framework or how to create it in Swift or SwiftUI?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论