繁体   English   中英

iOS 7与iOS 8自动停放问题

[英]iOS 7 vs iOS 8 autoloayout issues

我无法解决iOS 7的自动版式问题。请查看屏幕截图。

  1. iOS 8屏幕截图。 没问题,一切看起来都应该正常并且可以正常工作。

iOS 8屏幕截图

  1. iOS 7屏幕截图。 注意UI工件。 奇怪的是,每次我运行该应用程序时它们都不相同。 当它们发生时,它们当然会干扰应用程序的响应性,等等。

iOS 7屏幕截图与工件

  1. 而且总是发生这种情况时,我会得到相同的自动布局错误。 总是带有_UILayoutGuide。 我尝试了一切,但无法解决此问题。 注意:在iOS 8上,我没有任何问题。

自动布局错误

我用自动布局> 20次重新设计了整个UI(从零开始)。 而且,在iOS8上运行该应用程序永远不会有问题,总是在iOS 7上出现与上述相同的错误。 所有UI和约束都在界面构建器(storyboard)内完成。 所有按钮都是包含UILabel的UIViews就是这样。

有什么想法下一步可以尝试吗?

编辑:在此处复制/粘贴消息:

2015-04-15 10:01:47.725 SiolBoxDaljinec[52380:607] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7b09a520 V:|-(0)-[UIView:0x7b099c80]   (Names: '|':UIView:0x7b099ff0 )>",
    "<NSLayoutConstraint:0x7b09a550 UIView:0x7b099c80.height == 0.833333*UIView:0x7b099ff0.height + 20>",
    "<NSLayoutConstraint:0x7b09a5b0 V:[UIView:0x7b099c80]-(0)-[UIView:0x7b099260]>",
    "<NSLayoutConstraint:0x7b09a610 UIView:0x7b099260.height == 0.166667*UIView:0x7b099ff0.height - 20>",
    "<NSLayoutConstraint:0x7b09a640 V:[UIView:0x7b099260]-(0)-[_UILayoutGuide:0x7b09a220]>",
    "<_UILayoutSupportConstraint:0x7b099f70 V:[_UILayoutGuide:0x7b09a220(0)]>",
    "<_UILayoutSupportConstraint:0x7b096a50 _UILayoutGuide:0x7b09a220.bottom == UIView:0x7b099ff0.bottom>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7b09a640 V:[UIView:0x7b099260]-(0)-[_UILayoutGuide:0x7b09a220]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

编辑2:

在更仔细地检查了所有内容之后,我发现问题是UIView,其中包含OK / Circle(和V + / V- / P + / P-按钮)按钮。 如果删除此UIView中的每个按钮,则不会再有自动布局异常。 到现在为止我还可以做到...

编辑3:

在进一步研究问题之后,我发现了其他可能是问题的问题。 查看下面的代码(当用户单击两个底部栏按钮之一时,会发生这种情况):

func resizeAndRepositionViewBelowViewAndThenSlideIn(sizeReference:UIView, viewControllerToPosition:UIViewController, viewReference:UIView, button:UIButton)
    {
        viewControllerToPosition.view.frame = CGRectMake(0.0, viewReference.frame.origin.y, sizeReference.frame.width, sizeReference.frame.height)
        viewControllerToPosition.view.alpha = 0.0

        self.view.addSubview(viewControllerToPosition.view)
        button.setImage(InternalViewControllersButtonImagesSelected[button.tag], forState: UIControlState.Normal)

        UIView.animateWithDuration(NSTimeInterval(MenuAnimationDuration), delay: 0.0, options: .CurveEaseOut, animations: {

            viewControllerToPosition.view.alpha = 1.0
            viewControllerToPosition.view.frame = sizeReference.frame

            }, completion: { finished in

                self.InternalViewPresented = viewControllerToPosition
                self.SubViewAnimationInProgress = false
        })
    }

更改视图的框架后 ,似乎自动布局会损坏 (在我的情况下,该根视图中有2个容器视图)。

您的约束条件过高。 我不知道为什么在iOS 8上不会出现此问题,但是可以清楚地从屏幕快照的限制列表中看到问题所在。 按顺序,我们可以(我将使用视图的内存地址的后两位来标识它们):

  • 视图顶部80-

     V:|-(0)-[UIView:0x7b099c80] 
  • 视野高度80-

     UIView:0x7b099c80.height == ... 
  • 视图80的底部和视图60的顶部之间的空间-

     V:[UIView:0x7b099c80]-(0)-[UIView:0x7b099260]> 
  • 视线高度60-

     UIView:0x7b099260.height == ... 
  • 视图底部60-

     V:[UIView:0x7b099260]-(0)-[_UILayoutGuide:0x7b09a220]> 

太多的限制。 您可以设置某物的顶部和高度, 顶部和底部,但一定不能设置顶部高度底部-因为如果算术结果相差很小,那么这些要求将无法同时满足。

OMG最终看起来像是这样的问题:

iOS长宽比约束在iOS7上打破,在iOS8上有效

那就是-长宽比+相等(高度等)的某些组合在iOS7上被破坏了。

暂无
暂无

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

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