我正在尝试制作滚动动画。在下面的代码中,detailText
是UITextView
。不知道为什么UIView.animate
函数不起作用。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 1.0, delay: 0.0,
usingSpringWithDamping: 0.6,
initialSpringVelocity: 6.0,
options: [.curveEaseIn], animations: {
let rangeOfTag = (self.detailText.text as NSString).range(of: "satisfactorily")
self.detailText.scrollRangeToVisible(rangeOfTag)
}, completion: nil)
我尝试了以下方法:
override func viewDidLayoutSubviews()
创建弹簧没有成功。有什么想法吗?
答案 0 :(得分:0)
您可以使用此片段来获取振动。
UIView.animate(withDuration: 3.0, delay: 0.0,
usingSpringWithDamping: 0.1,
initialSpringVelocity: 0.9,
options: [.curveEaseIn, .overrideInheritedCurve], animations: {
let rangeOfTag = (self.detailText.text as NSString)
.range(of: "satisfactorily")
let glyRange = self.detailText.layoutManager.glyphRange(forCharacterRange: rangeOfTag, actualCharacterRange: nil)
let rect = self.detailText.layoutManager.lineFragmentRect(forGlyphAt: NSMaxRange(glyRange), effectiveRange: nil)
self.detailText.scrollRectToVisible(rect, animated: false)
}, completion: nil)