Home CGAffineTransform scale with slider
Reply: 1

CGAffineTransform scale with slider

Joe
1#
Joe Published in 2017-11-15 01:00:58Z

I have a UISlider which goes from 0 to 275. I want to use the slider to scale an UIImageView.

When my slider value is 0 my UIImageView should have the original size (scaleX: 1, scaleY: 1).

When my slider value is 275 my UIImageView should scale to 0.85.

Can someone suggest a good formula to calculate the scale value in relationship with slider value?

Something like this

let scale = slider.value >= 275 ? 0.85 : 1
imageView.transform = CGAffineTransform(scaleX: scale, scaleY: scale)

But I have some trouble making the scale dynamic based on slider value.

vacawama
2#
vacawama Reply to 2017-11-15 01:06:58Z

You could use a linear scale such as:

let scale = 1.0 - slider.value/275.0 * 0.15
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305318 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO