iOS中的垂直UISlider具有自动布局功能 [英] Vertical UISlider in iOS with autolayout

查看:447
本文介绍了iOS中的垂直UISlider具有自动布局功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的iPad应用程序要求,我要垂直显示UISlider。

我正在使用iOS7编译器,部署目标是iOS6。

在故事板我添加了宽度为600像素的水平UISlider。我在视图控制器中创建了IBOutlet。我没有设置任何自动布局约束。我正在使用以下代码进行旋转并使其垂直。

As per my iPad app requirement, i've to show the UISlider vertically.
I'm using iOS7 compiler and deployment target is iOS6.
In the story board I added horizontal UISlider of width 600 pixels. I created IBOutlet in my view controller. I didn't set any auto layout constraints. I'm using the below code to rotate and make it vertical.

self.slider.transform = CGAffineTransformMakeRotation(M_PI_2);

旋转之前和之后我打印滑块的框架尺寸是正确的。但滑块看起来不合适。它只显示中心的旋钮。如何旋转UISlider?

After and before rotation I'm printing the frame size of the slider which is correct. But the slider is not looking proper. Its just showing only knob in the center. How can I rotate the UISlider?


推荐答案

我让它以这种方式工作:

I got it to work this way:

viewDidLoad:我添加了

[self.slider removeConstraints:self.slider.constraints];
[self.slider setTranslatesAutoresizingMaskIntoConstraints:YES];

因此在旋转滑块之前调用它

so that it's called before rotating the slider with

self.slider.transform=CGAffineTransformRotate(self.slider.transform,270.0/180*M_PI);

并且无需删除并重新添加到superview。

and there is no need to remove and re-add it to superview.

这篇关于iOS中的垂直UISlider具有自动布局功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆