Question

I have 3 UIViews which are scaled by a single UISlider. They each have different min scales (0.5, 0.9 and 0.35). As the slider moves from 1.0 to 0.0 I would like to scale each of these view proportionately. For example view 1 is 100 x 100 and when the slider is at 0.0 it should be 50 x 50. View 2 is 100 x 100 and when the slider is 0.0 it should be 90 x 90. They should all scale smoothly in time with each each other, just at different rates.

Was it helpful?

Solution

Here the equation:

float side = (100 * minScale) + (1.0 - minScale) * 100 * sliderValue;

So for example:

float minScale = 0.9;
float sliderValue = 0.5

float side = (100 * minScale) + (1.0 - minScale) * 100 * sliderValue;
//side = 90 + (0.10 * 100 * 0.5) = 90 + 5 = 95

OTHER TIPS

Try this:

- (double)scaleFromSliderValue:(double)sliderValue minScale:(double)minScale {
    return minScale + sliderValue * (1 - minScale);
}

- (void)sliderValueChanged:(UISlider *)slider {
   double scale1 = [self scaleFromSliderValue:slider.value minScale:0.5];
   view1.transform = CGAffineTransformMakeScale(scale1, scale1);

   double scale2 = [self scaleFromSliderValue:slider.value minScale:0.9];
   view2.transform = CGAffineTransformMakeScale(scale2, scale2);

   double scale3 = [self scaleFromSliderValue:slider.value minScale:0.35];
   view3.transform = CGAffineTransformMakeScale(scale3, scale3);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top