UIPickerView selectRow:inComponent:animated 具有平滑的动画

发布于 2024-10-22 03:55:38 字数 390 浏览 3 评论 0原文

我试图创建一个老虎机(输入老虎机,但你可以说在 UI 级别它会像老虎机一样工作)所以我使用 UIPickerView 以及我如何使其循环。但是当我使用带有动画值 YES 的函数 selectRow:inComponent:animated: 旋转它时。它的动画有点马虎,或者你可以说当我们用手旋转 UIpickerview 时它不够酷。

动画马虎意味着,当我们用手移动 UIPickerView 时,它会在动画结束时降低速度,这种效果看起来非常好,但是当我使用函数 selectRow:inComponent:animated: 我无法获取该动画。

有没有办法得到这个动画???

i was trying to create a Slot machine(type off slot machine but you can say at UI level it will work like Slot machine) So I use UIPickerView and some how i made it circular. But when i rotate it using function selectRow:inComponent:animated: with animated value YES. its animation is bit sloppy or you can say that not cool enough when we spin UIpickerview from hands.

Sloppy animation means, when we move UIPickerView with hands, it decreases its speed at the end of animation and this effect looks very good but when I use function selectRow:inComponent:animated: I can't get that animation.

Is there a way to get that animation???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好久不见√ 2024-10-29 03:55:38

您是否尝试获取 uipickerview 的递归描述?
我认为有些地方应该有一个滚动视图。
尝试获取滚动视图引用并使其使用自定义动画滚动到所需的位置。要获取视图层次结构,请尝试在选择器视图上使用递归描述。
这只是一个提示。
希望这有帮助。

Did you try getting the recursive description the uipickerview?
I think that some where there should be a scrollview inside.
try getting the scrollview reference and make it scroll to the desired position with a custom animation. To get the view hierarchy try using recursive description on the picker view.
It's just a hint.
Hope that this helps.

长伴 2024-10-29 03:55:38

不确定它是否仍然相关,但当我偶然发现同样的问题时,我为 UIPickerView 做了一个扩展,并伪造了缓慢的动画。

extension UIPickerView {

    func slowSelectRow(_ row: Int, inComponent component: Int = 0) {
        let currentSelectedRow = selectedRow(inComponent: component)

        guard currentSelectedRow != row else {
            return
        }

        let diff = (currentSelectedRow > row) ? -1 : 1
        let newRow = currentSelectedRow + diff
        selectRow(newRow, inComponent: component, animated: true)

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
            self.slowSelectRow(row, inComponent: component)
        }
    }
}

Not sure if it is still relevant but as I stumbled on the same issue I made an extension for the UIPickerView with fakes the slow animation.

extension UIPickerView {

    func slowSelectRow(_ row: Int, inComponent component: Int = 0) {
        let currentSelectedRow = selectedRow(inComponent: component)

        guard currentSelectedRow != row else {
            return
        }

        let diff = (currentSelectedRow > row) ? -1 : 1
        let newRow = currentSelectedRow + diff
        selectRow(newRow, inComponent: component, animated: true)

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
            self.slowSelectRow(row, inComponent: component)
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文