Xcode:如何在不变形的情况下旋转滑块或进度视图

时间:2013-06-27 17:44:37

标签: iphone objective-c xcode

我只想在我的iPhone应用程序中设置vertical sliderprogressBar,但每次我尝试将它们转换为将它们旋转90度时,它们会消失或拉伸。有办法防止这种情况吗?我想要的只是滑块和进度条显示为垂直但保持相同的大小并具有相同的外观。

增加:

我在这里找到了如何旋转的代码:

    define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
    [self.progressView setTransform:CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(angle))];

我正在slider中创建progress viewstoyboard,将其链接到我在ViewController.m中声明的变量。随着“角度”增加progress ba r,slider越来越伸展。最后,当我旋转90时,progress bar消失,slider只显示为拇指图像,但没有slider bar

#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    //Create a transformation with just the rotation
    CGAffineTransform transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));

    //Now apply our scale
    transform = CGAffineTransformScale(transform, 2, 2);

    //Now set the transform on the object to the combined rotation/scale transform.
    [self.shield2 setTransform: transform];

    CGAffineTransform sliderRotation = CGAffineTransformIdentity;
    sliderRotation = CGAffineTransformRotate(sliderRotation, -DEGREES_TO_RADIANS(89));

    self.shield.transform = sliderRotation;
}

1 个答案:

答案 0 :(得分:2)

自动布局不适合变换。禁用自动布局或删除转换后的控件和其他视图之间的任何约束,并“手动”定位控件。