使用UISlider扩展UIView

时间:2012-06-04 16:30:27

标签: ios uislider cgaffinetransformscale

我正在尝试使用UISlider扩展UIView,但结果并不适合这种方法:

- (void)setScale:(float)scale {
   CGAffineTransform transform = CGAffineTransformScale(myView.transform, scale, scale);
            myView.transform = transform;

}

感谢

1 个答案:

答案 0 :(得分:2)

您希望根据身份转换(代表没有任何更改的对象)更改比例。此代码有效:

- (void)sliderDidChangeValue:(id)sender
{
    // the slider
    UISlider *slider = sender;

    // get your view or use the ivar if you have it in one
    UIView *view = [self.view viewWithTag:12];

    CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity, slider.value, slider.value);
    view.transform = transform;
}

创建滑块时,如果视图以全尺寸开始,则可能需要将值设置为1.