How to get the exact point of objects in swift?

微笑、不失礼 提交于 2019-12-08 10:43:07

问题


I'm using a UIProgressView and want to stick a image subview to the progress % as in the image below:

I want to get the co-ordinate of the progress tint and red subview as in the figure to "stick" with the progress tint, whatever the progress will be..


回答1:


You can start by vertically centering the image view with the progress view using constraints or programmatically like below.

imageView.center.y = progressView.center.y

Then where ever you are updating the progress, after you can calculate the center x coordinate for the image view using the adjusted progress and width of the progress view.

imageView.center.x = progressView.progress * progressView.frame.width

Although you may need to add padding if the progress view's super view is not the same width.

OR

You could consider using a UISlider; it comes with a progress-bar-like track and a thumb slider that you can customise. This way, you can even have user interaction if need be - otherwise user interaction can be disabled and you can set the progress programmatically.



来源:https://stackoverflow.com/questions/41197694/how-to-get-the-exact-point-of-objects-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!