panghaijiao / HJDanmaku-Swift

A high performance danmaku engine for iOS
http://www.olinone.com/?p=755
MIT License
20 stars 7 forks source link

动态改变 font size #4

Closed conscientiousness closed 5 years ago

conscientiousness commented 5 years ago

您好,想请教,目前在实作动态改变弹幕字的大小,下面是透过slider调整后,透过NotificationCenter触发的func,调整cell大小显示没问题,不过在屏幕上的弹幕准备要移出屏幕时有些奇怪(还没移出屏幕就由右到左逐渐消失),估计是改变frame size导致原本计算好的数值不一致,不知道有沒有refresh目前屏幕上弹幕的方法,谢谢

@objc func danmakuFontSizeChanged(_ notification: Notification) {
        guard let rate = notification.object as? Float, rate > 0 else { return }

        danmakuView.visibleCells.forEach {
            if let model = danmakuView.danmakuForVisibleCell($0) as? danmakuModel {
                $0.textLabel.attributedText = NSAttributedString(string: model.danmaku.text, attributes: model.attributes)

                if let newWidth = danmakuView.dataSource?.danmakuView(danmakuView, widthForDanmaku: model) {
                    $0.frame = CGRect(x: $0.frame.origin.x, y: $0.frame.origin.y, width: newWidth, height: $0.frame.size.height )
                }
            }
        }
    }
panghaijiao commented 5 years ago

能否只改字体,不改frame了?目前暂不支持这种需求,如果想修正,只能清空屏幕,重新全部渲染

conscientiousness commented 5 years ago

感谢回覆,先给定最大倍率的width解决