简体   繁体   English

使用UISlider更改UIImageView高度

[英]change UIImageView height with UISlider

I have 2 UIImageViews with a picture of a thermometer with no color and one with color. 我有2个UIImageViews ,其中有一个没有颜色的温度计的图片,一个有颜色的温度计。 I want to set the height of the colored UIImageView dynamic with a UISlider . 我想用UISlider设置彩色的UIImageView动态的UISlider

So when the App starts I just want to show the thermometer without any color, when I slide my UISlider I want the colored UIImageView to increase the height. 因此,当应用程序启动时,我只想显示没有任何颜色的温度计,当我滑动UISlider我希望彩色的UIImageView增加高度。 It should increase from 0 to full height(460). 它应该从0增加到全高(460)。

How can I do that? 我怎样才能做到这一点?

This is just an example of a more more complex situation. 这只是更复杂情况的一个例子。

I've tried with the following, but it just scales the whole picture, I just want to increase the height. 我尝试了以下方法,但是它只是缩放整个图片,我只想增加高度。

- (IBAction)my_slider:(UISlider *)sender {

    [self.thermo_color setTransform:CGAffineTransformMakeScale(sender.value, sender.value)];

}

Check this link for an example photo: http://i.stack.imgur.com/PARUT.jpg 检查此链接以获取示例照片: http : //i.stack.imgur.com/PARUT.jpg

Thank You. 谢谢。

Te Controller structure: 控制器结构:

-MainView
--UIImageView *themFull (full image with full color)
--UIView *viewAnimated (a white view that you transform for the animation effect)
--UIImageView *themEmpty (empty Image of thermometer)

This Is the good way for do that: 这是这样做的好方法:

- (IBAction)my_slider:(UISlider *)sender {

    dispatch_async(dispatch_get_main_queue(), ^{

        [self.viewAnimated setFrame:CGRectMake(self.viewAnimated.frame.origin.x,
                                                self.viewAnimated.frame.origin.y,
                                                self.viewAnimated.frame.size.width,
                                                self.viewAnimated.frame.size.width / sender.value)];

    });
}

the size of view have to be the same of the your UIImageViews 视图的大小必须与您的UIImageViews相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM