本文介绍了自动布局在导航控制器,UISegmentedControl:在iOS7好的,坏在iOS6的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关导航控制器我喜欢朝下方放置在一个视图从上一些控件。我使用的自动布局和添加的约束,这样的观点有一个垂直间隙给对方。这看起来不错的iOS7和iOS6的在普通视图控制器,也为iOS7在导航控制器;但错在iOS6的。该UISegmentedControl显示错了。见截图。

For a navigation controller I like to have a few controls placed in a view from top towards the bottom. I am using auto layout and added constraints, so that the views have a vertical gap to each other. This looks nice for iOS7 and iOS6 in a normal view controller, also for iOS7 in a navigation controller; but wrong in iOS6. The UISegmentedControl shows up wrong. See the screenshots.

它看起来像UISegmentedControl的较大高度不考虑为iOS6的图。同时切换从3.5英寸到4英寸的屏幕,当它被转移出来的地方。

It looks like the larger height of the UISegmentedControl is not taken into account for iOS6 view. Also it gets shifted out of place when switching from 3.5 inch to 4 inch screen.

请注意,这只是发生在一个导航控制器视图。在故事板的导航控制器我设置上栏不透明导航栏。
上面的按钮有约束顶层空间顶部布局指南。所有其他控件有约束顶层空间来......(他们上面的控制)。

Note that this only occurs in a navigation controller view. In the storyboard for the navigation controller I set Top Bar to "Opaque Navigation Bar".The upper button has a constraint "Top Space to Top Layout Guide". All other controls have a constraint "Top Space to ...." (control above them).

是否有任何已知的修复,我可以申请哪些?

Are there any known fixes which I could apply?

可能是什么问题? (我对汽车的布局相当新手。)或者只是我有一个错误来解决不知何故?

What could be wrong? (I'm quite a newbie for auto layout.) Or is it just a bug which I have to work around somehow?

编辑:

我试过把分段控制在一个额外的观点,但没有帮助。

I tried placing the segmented control in an extra view, but that did not help either.

我的高度约束设置为分段控制和的方式,确实帮助。但这种设置相同的高度,以既iOS6的和iOS7为分段控制。我的工作,现在周围是改变/在code添加高度约束当视图加载和设置取决于iOS版本的值。还有没有其他的建议?

I could set a height constraint to the segmented control and that did help in a way. But this sets the same height to both iOS6 and iOS7 for the segmented control. My work around would now be to change/add the height constraint in code when the view loads and set a value depending on the iOS version. Are there other recommendations?

截图:

在导航控制器,鉴于iOS6的:

In Navigation Controller, iOS6 view:

在导航控制器,iOS7观点:

In Navigation Controller, iOS7 view:

在一个正常视图控制器,查看iOS6的:

In a "normal" view controller, iOS6 view:

在一个正常视图控制器,iOS7观点:

In a "normal" view controller, iOS7 view:

推荐答案

我的工作围绕到目前为止是添加取决于iOS版本的高度限制。在iOS6的分段控件的高度是43,在iOS7高度为28 code:

My work around so far is to add a height constraint depending on the iOS version. In iOS6 the height of the segmented control is 43, in iOS7 the height is 28. The code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    int segCtrlHeight = (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
          ? 28 : 43;
    NSLayoutConstraint *lc = [NSLayoutConstraint constraintWithItem:self.segCtrl attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:segCtrlHeight];
    [self.view addConstraint:lc];
}

我回答我的问题现在。我会很高兴,如果有人想出了一个更好的答案(preferably无需添加自定义code)。

I'm answering my own question for now. I'd be glad if someone comes up with a better answer (preferably without having to add custom code).

这篇关于自动布局在导航控制器,UISegmentedControl:在iOS7好的,坏在iOS6的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:15