以不同的速率调整多个UIView的大小

时间:2014-04-28 23:14:54

标签: ios objective-c uiview

我有3个UIViews,它们由一个UISlider缩放。它们各自具有不同的最小刻度(0.5,0.9和0.35)。当滑块从1.0移动到0.0时,我想按比例缩放每个视图。例如,视图1是100 x 100,当滑块是0.0时,它应该是50 x 50.视图2是100 x 100,当滑块是0.0时,它应该是90 x 90.它们应该在每个时间内平滑地缩放彼此,只是以不同的速度。

2 个答案:

答案 0 :(得分:1)

这里的等式:

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

例如:

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

答案 1 :(得分:0)

试试这个:

- (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);
}