Swift:自定义滑块(滑动解锁样式)
我正在尝试在已知幻灯片中实现一个滑块,以解锁旧 iPhone 的样式,以便在我的 swift 应用程序中执行操作。拖动时滑块应更改背景颜色并更改内部文本。当用户拖动到最后时,thumbView 应粘在右侧并等待确认(某些事件)进入,最终呈现一个新视图。
滑块应如下所示:
我在互联网,但没有什么可以接近的我想做。我该怎么做呢?我的猜测是视图与拖动事件的组合,但我觉得一定有一种更简单的方法。有什么想法吗?
I am trying to implement a slider in the known slide to unlock style from older iphones to perform an action inside my swift app. The Slider should change background color and change the text inside while dragging. When the user drags til the end, the thumbView should stick to the right side and wait for a confirmation (some event) coming in to finally present a new view.
The slider should look something like this:
I have found a few things on the internet but nothing that comes close to what I want to do. How would I go about doing this? My guess would be a combination of views with drag events but I feel like there must be an easier way. Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许是一个 UISlider,在带有文本和颜色的矩形视图上有透明轨道。您可以将图像设置为 UISlider 的拇指,并在值更改以及用户触摸并释放它时接收事件。
例如,您可以使用它,当用户在除轨道末尾之外的任何位置释放按钮时,将拇指动画回到开头。另外,您可以将滑块的值设置为 0 到 1 并使用它来计算颜色,以便其平滑变化。
当用户在轨道末端释放时,您激活活动指示器并开始呈现下一个视图的过程......
尽管这是可能的,但我想我会尝试使用平移手势进行自定义控件。它会给你更多的控制权,例如,你可以选择当返回到发布开始时拇指图像的动画方式......我不认为你可以使用 UISlider 的 setValue(animated:) 来做到这一点。
Maybe a UISlider with a transparent track on a rectangle view with your text and color. You can set your image as the UISlider's thumb and receive events as the value changes and when the user touches and releases it.
You can use that to for example, animate the thumb back to the start when the user releases on any place except the end of the track. Also, you can set the slider's value from 0 to 1 and use it to calculate the color, so it changes smoothly.
When the user releases on the end of the track, you activate the activity indicator and start your process to present the next view....
Even though this is a possibility, I think I'd try doing a custom control using a pan gesture. It'd give you more control and you could for example choose how the thumb image animates when going back to the start on release.... I dont' think you can do that with UISlider's setValue(animated:).