iOS的纵横比约束的突破iOS7,适用于iOS8上 [英] iOS aspect ratio constraint breaks on iOS7, works on iOS8

查看:307
本文介绍了iOS的纵横比约束的突破iOS7,适用于iOS8上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我在它的高度会从它的宽度采用宽高比计算约束的方式建立一个UIView的约束。它完美的iOS8上与每一个设备的屏幕尺寸(3.5,4,4.7,5.5),但它会导致应用程序崩溃每iOS7设备上。

我认为它的纵横比限制,因为如果我有一个固定的高度约束代替它,它没有了(这显然很糟糕某些设备上)。

崩溃

堆栈跟踪是非常长的,所以我只是复制它的部分。

感谢您提前为您的帮助!

 目标:{目标0x7f9d90da33c0:其中,750:4692,251:2936,250:367> +< 251:-1> * 0x7f9d90c06220.marker {ID:592} +< 251:-1> * 0x7f9d90c24420.marker {ID:599} +< 251:-1> * 0x7f9d90c25650.marker {ID:594 } + LT; 251:-1> * 0x7f9d90c27ad0.marker {ID:597} + LT; 750:-1> * 0x7f9d90c3b270.marker {ID:483} + LT; 250:-3.9875> * 0x7f9d90c43e40.marker {ID :618} +< 250:-3.9875> * 0x7f9d90c43e90.marker {ID:620} +< 750:-4> * 0x7f9d90c442e0.marker {ID:479} +< 251:1> * 0x7f9d90c464b0.marker { ID:485} +< 251:-1> * 0x7f9d90c46bf0.marker {ID:504} +< 251:-1> * 0x7f9d90c46c90.marker {ID:508} +< 251:-1> * 0x7f9d90c46ce0.marker {ID:510} +< 251:-1> * 0x7f9d90c46d80.marker {ID:514} +< 251:-2> * 0x7f9d90c4aa60.marker {ID:623} +< 251:-2> * 0x7f9d90c4aab0。标记{ID:625} + LT; 251:-2,250:-3.9875> * 0x7f9d90c4ab50.marker {ID:631} + LT; 251:-2,250:-3.9875> * 0x7f9d90c4abf0.marker {ID: 634} +< 251:4,250:3.9875> * 0x7f9d90c4ac40.marker {ID:637} +< 251:4,250:3.9875> * 0x7f9d90c4ac90.marker {ID:642} +< 750:1 ,251:1> * 0x7f9d90c4c530.negError {ID:645} +< 750:1,251:1> * 0x7f9d90c4cb20.posErrorMarker {ID:646} +< 750:1,251:1> * 0x7f9d90c530f0.negError { ID:649} +< 750:1,251:1> * 0x7f9d90c53150.negError {ID:651} +< 750:1,250:1> * 0x7f9d90c53820.posErrorMarker {ID:652} +< 750:1 ,250:1> * 0x7f9d90c538a0.posErrorMarker {ID:654} +< 750:1,250:1> * 0x7f9d90c53fd0.posErrorMarker {ID:656} +< 750:1,250:1> * 0x7f9d90c54070.posErrorMarker { ID:658} +< 750:1,251:1> * 0x7f9d90c54650.negError {ID:661} +< 750:1> * 0x7f9d90c546b0.negError {ID:663} +< 251:1> * 0x7f9d90c546b0。 posErrorMarker {ID:662} +< 750:1> * 0x7f9d90c55230.negError {ID:665} +< 251:1> * 0x7f9d90c55230.posErrorMarker {ID:664} +< 750:1,251:1> * 0x7f9d90c552b0.negError {ID:667} +< 750:1,251:1> * 0x7f9d90d34300.posErrorMarker {ID:916} +< 750:1> * 0x7f9d90de48a0.marker {ID:738} +< 250: - 1> * 0x7f9d90de48f0.marker {ID:740} +< 250:-1> * 0x7f9d90de4940.marker {ID:744} +< 750:1> * 0x7f9d90de4990.marker {ID:745} +< 750:1&GT * 0x7f9d90de4c70.marker {ID:718} + LT; 750:1> * 0x7f9d90de4cc0.marker {ID:720} + LT; 250:-1

...

  Integralization调整:
0x7f9d93042a90.marker {ID:532}< NSLayoutConstraint:0x7f9d93042a90的UIView:0x7f9d9303d590.width == 1.50943 *的UIView:0x7f9d9303d590.height> - > 0.132066
0x7f9d93042c70.marker {ID:546}< NSLayoutConstraint:0x7f9d93042c70的UIButton:0x7f9d90de27a0.height ==的UIButton:0x7f9d93018ab0.height> - > 1.000000
0x7f9d93042d60.marker {ID:552}< NSLayoutConstraint:0x7f9d93042d60的UIButton:0x7f9d9303dbf0.width ==的UIButton:0x7f9d93018ab0.width> - > -1.000000
0x7f9d93042db0.marker {ID:554}< NSLayoutConstraint:0x7f9d93042db0的UIButton:0x7f9d9303dbf0.height ==的UIButton:0x7f9d93033b40.height> - > 1.000000
0x7f9d93042ea0.m​​arker {ID:562}< NSLayoutConstraint:0x7f9d93042ea0的UIButton:0x7f9d93033b40.width ==的UIButton:0x7f9d9303c500.width> - > -1.000000
0x7f9d930431c0.marker {ID:581}< NSLayoutConstraint:0x7f9d930431c0的UIButton:0x7f9d9303c500.height ==的UIButton:0x7f9d93045880.height> - > 1.000000  统计:
    195行。变量数:
          1 - > 59
          2 - > 28
          3 - > 3
          4 - > 7
          5 - > 4
          6 - > 3
          7 - > 3
          8 - > 4
          9 - > 8
         10 - > 10
         11 - > 11
         12 - > 10
         13 - > 7
         14 - > 2
         15 - > 3
         16 - > 10
         17 - > 17
         18 - > 6
}: 内部错误。找不到传入头的UIView传出的行头:0x7f9d930332a0.Height {ID:981},这不应该发生。
***第一掷调用堆栈:

    0的CoreFoundation 0x000000011284d495 __exception preprocess + 165
    1 libobjc.A.dylib 0x000000011220699e objc_exception_throw + 43
    2的CoreFoundation 0x000000011284d2ad + NSException提高:格式:] + 205
    3基金会0x0000000110dfb054 - [NSISEngine minimizeConstantInObjectiveRowWithHead:] + 178
    4基金会0x0000000110dfaf22 - [NSISEngine优化] + 147
    5基金会0x0000000110f432e3 - [NSISEngine withBehaviors:performModifications:] + 192
    6 UIKit的0x000000011126f889 - [UIView的(层次)_postMovedFromSuperview:] + 321
    7 UIKit的0x000000011126df42 __UIViewWasRemovedFromSuperview + 206
    8 UIKit的0x000000011126db9e - [UIView的(层次)removeFromSuperview] + 218
    9 UIKit的0x0000000111330069 - [UINavigationController的navigationTransitionView:didEndTransition:fromView:toView:] + 320
    10 UIKit的0x0000000111328fdd __49- [UINavigationController的_startCustomTransition:] _ block_invoke + 138
    11 UIKit的0x000000011187ec2a - [_ UIViewControllerTransitionContext completeTransition:] + 78
    12 UIKit的0x0000000111211da4 __53 - [_ UINavigationParallaxTransition animateTransition:] _ block_invoke103 + 605
    13 UIKit的0x00000001112746e8 - [UIViewAnimationBlockDelegate _didEndBlockAnimation:完成:上下文:] + 299
    14 UIKit的0x000000011126068e - [UIViewAnimationState sendDelegateAnimationDidStop:完成:] + 235
    15 UIKit的0x0000000111260941 - [UIViewAnimationState animationDidStop:完成:] + 78
    16 UIKit的0x000000011ef6d4b7 - [UIViewAnimationStateAccessibility(SafeCategory)animationDidStop:成品:] + 48
    17 QuartzCore 0x0000000110ac9134 _ZN2CA5Layer23run_animation_callbacksEPv + 310
    18 libdispatch.dylib 0x000000011327772d _dispatch_client_callout + 8
    19 libdispatch.dylib 0x00000001132673fc _dispatch_main_queue_callback_4CF + 354
    20的CoreFoundation 0x00000001128ab289 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    21的CoreFoundation 0x00000001127f8854 __CFRunLoopRun + 1764
    22的CoreFoundation 0x00000001127f7d83 CFRunLoopRunSpecific + 467
    23 GraphicsServices 0x0000000114223f04 GSEventRunModal + 161
    24 UIKit的0x000000011121be33 UIApplicationMain + 1010
    25 Playchat 0x000000010fa89513主+ 115
    26 libdyld.dylib 0x00000001134fa5c9启动+ 1

的libc ++ abi.dylib:类型NSException的未捕获的异常终止


解决方案

这是一个恼人的bug,花了我很多时间为好。我有完全相同的问题,应用程序在iOS 8的工作正常,但在iOS的7.1坠毁。问题是在一个滚动视图的纵横比限制。尝试了很多不同的东西后,这个问题终于解决了:

的崩溃似乎是一个浮点计算失败在某些点的结果。就我而言,我已经定义16的长宽比:9或相当9:16,即达0.5625。
从0.5625乘数更改为0.5624解决了这一问题后,没有更多的崩溃从那以后出现。

In my app, I have setup a UIView's constraints in a way where its height gets calculated from its width using the aspect ratio constraint. It works perfectly on iOS8 with every device screen size (3.5, 4, 4.7, 5.5), but it causes the app to crash on every iOS7 device.

I assume it's the aspect ratio constraint, because if I replace it with a fixed height constraint, it doesn't crash anymore (obviously it looks bad on some devices).

The stack trace is extremely long, so I'm only copying parts of it.

Thank you in advance for your help!

Objective: {objective 0x7f9d90da33c0: <750:4692, 251:2936, 250:367> + <251:-1>*0x7f9d90c06220.marker{id: 592} + <251:-1>*0x7f9d90c24420.marker{id: 599} + <251:-1>*0x7f9d90c25650.marker{id: 594} + <251:-1>*0x7f9d90c27ad0.marker{id: 597} + <750:-1>*0x7f9d90c3b270.marker{id: 483} + <250:-3.9875>*0x7f9d90c43e40.marker{id: 618} + <250:-3.9875>*0x7f9d90c43e90.marker{id: 620} + <750:-4>*0x7f9d90c442e0.marker{id: 479} + <251:1>*0x7f9d90c464b0.marker{id: 485} + <251:-1>*0x7f9d90c46bf0.marker{id: 504} + <251:-1>*0x7f9d90c46c90.marker{id: 508} + <251:-1>*0x7f9d90c46ce0.marker{id: 510} + <251:-1>*0x7f9d90c46d80.marker{id: 514} + <251:-2>*0x7f9d90c4aa60.marker{id: 623} + <251:-2>*0x7f9d90c4aab0.marker{id: 625} + <251:-2, 250:-3.9875>*0x7f9d90c4ab50.marker{id: 631} + <251:-2, 250:-3.9875>*0x7f9d90c4abf0.marker{id: 634} + <251:4, 250:3.9875>*0x7f9d90c4ac40.marker{id: 637} + <251:4, 250:3.9875>*0x7f9d90c4ac90.marker{id: 642} + <750:1, 251:1>*0x7f9d90c4c530.negError{id: 645} + <750:1, 251:1>*0x7f9d90c4cb20.posErrorMarker{id: 646} + <750:1, 251:1>*0x7f9d90c530f0.negError{id: 649} + <750:1, 251:1>*0x7f9d90c53150.negError{id: 651} + <750:1, 250:1>*0x7f9d90c53820.posErrorMarker{id: 652} + <750:1, 250:1>*0x7f9d90c538a0.posErrorMarker{id: 654} + <750:1, 250:1>*0x7f9d90c53fd0.posErrorMarker{id: 656} + <750:1, 250:1>*0x7f9d90c54070.posErrorMarker{id: 658} + <750:1, 251:1>*0x7f9d90c54650.negError{id: 661} + <750:1>*0x7f9d90c546b0.negError{id: 663} + <251:1>*0x7f9d90c546b0.posErrorMarker{id: 662} + <750:1>*0x7f9d90c55230.negError{id: 665} + <251:1>*0x7f9d90c55230.posErrorMarker{id: 664} + <750:1, 251:1>*0x7f9d90c552b0.negError{id: 667} + <750:1, 251:1>*0x7f9d90d34300.posErrorMarker{id: 916} + <750:1>*0x7f9d90de48a0.marker{id: 738} + <250:-1>*0x7f9d90de48f0.marker{id: 740} + <250:-1>*0x7f9d90de4940.marker{id: 744} + <750:1>*0x7f9d90de4990.marker{id: 745} + <750:1>*0x7f9d90de4c70.marker{id: 718} + <750:1>*0x7f9d90de4cc0.marker{id: 720} + <250:-1

...

 Integralization Adjustments:
0x7f9d93042a90.marker{id: 532} [<NSLayoutConstraint:0x7f9d93042a90 UIView:0x7f9d9303d590.width == 1.50943*UIView:0x7f9d9303d590.height>] -> 0.132066
0x7f9d93042c70.marker{id: 546} [<NSLayoutConstraint:0x7f9d93042c70 UIButton:0x7f9d90de27a0.height == UIButton:0x7f9d93018ab0.height>] -> 1.000000
0x7f9d93042d60.marker{id: 552} [<NSLayoutConstraint:0x7f9d93042d60 UIButton:0x7f9d9303dbf0.width == UIButton:0x7f9d93018ab0.width>] -> -1.000000
0x7f9d93042db0.marker{id: 554} [<NSLayoutConstraint:0x7f9d93042db0 UIButton:0x7f9d9303dbf0.height == UIButton:0x7f9d93033b40.height>] -> 1.000000
0x7f9d93042ea0.marker{id: 562} [<NSLayoutConstraint:0x7f9d93042ea0 UIButton:0x7f9d93033b40.width == UIButton:0x7f9d9303c500.width>] -> -1.000000
0x7f9d930431c0.marker{id: 581} [<NSLayoutConstraint:0x7f9d930431c0 UIButton:0x7f9d9303c500.height == UIButton:0x7f9d93045880.height>] -> 1.000000

  Statistics:
    195 rows. Variable counts:
          1 ->  59
          2 ->  28
          3 ->   3
          4 ->   7
          5 ->   4
          6 ->   3
          7 ->   3
          8 ->   4
          9 ->   8
         10 ->  10
         11 ->  11
         12 ->  10
         13 ->   7
         14 ->   2
         15 ->   3
         16 ->  10
         17 ->  17
         18 ->   6
}: internal error.  Cannot find an outgoing row head for incoming head UIView:0x7f9d930332a0.Height{id: 981}, which should never happen.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000011284d495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000011220699e objc_exception_throw + 43
    2   CoreFoundation                      0x000000011284d2ad +[NSException raise:format:] + 205
    3   Foundation                          0x0000000110dfb054 -[NSISEngine minimizeConstantInObjectiveRowWithHead:] + 178
    4   Foundation                          0x0000000110dfaf22 -[NSISEngine optimize] + 147
    5   Foundation                          0x0000000110f432e3 -[NSISEngine withBehaviors:performModifications:] + 192
    6   UIKit                               0x000000011126f889 -[UIView(Hierarchy) _postMovedFromSuperview:] + 321
    7   UIKit                               0x000000011126df42 __UIViewWasRemovedFromSuperview + 206
    8   UIKit                               0x000000011126db9e -[UIView(Hierarchy) removeFromSuperview] + 218
    9   UIKit                               0x0000000111330069 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 320
    10  UIKit                               0x0000000111328fdd __49-[UINavigationController _startCustomTransition:]_block_invoke + 138
    11  UIKit                               0x000000011187ec2a -[_UIViewControllerTransitionContext completeTransition:] + 78
    12  UIKit                               0x0000000111211da4 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke103 + 605
    13  UIKit                               0x00000001112746e8 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 299
    14  UIKit                               0x000000011126068e -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 235
    15  UIKit                               0x0000000111260941 -[UIViewAnimationState animationDidStop:finished:] + 78
    16  UIKit                               0x000000011ef6d4b7 -[UIViewAnimationStateAccessibility(SafeCategory) animationDidStop:finished:] + 48
    17  QuartzCore                          0x0000000110ac9134 _ZN2CA5Layer23run_animation_callbacksEPv + 310
    18  libdispatch.dylib                   0x000000011327772d _dispatch_client_callout + 8
    19  libdispatch.dylib                   0x00000001132673fc _dispatch_main_queue_callback_4CF + 354
    20  CoreFoundation                      0x00000001128ab289 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    21  CoreFoundation                      0x00000001127f8854 __CFRunLoopRun + 1764
    22  CoreFoundation                      0x00000001127f7d83 CFRunLoopRunSpecific + 467
    23  GraphicsServices                    0x0000000114223f04 GSEventRunModal + 161
    24  UIKit                               0x000000011121be33 UIApplicationMain + 1010
    25  Playchat                            0x000000010fa89513 main + 115
    26  libdyld.dylib                       0x00000001134fa5c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

解决方案

This is one annoying bug, cost me a lot of hours as well. I had the exact same problem, the app was working fine in iOS 8 but crashed in iOS 7.1. The problem was an aspect ratio constraint on a scroll view. After trying out a lot of different things, this finally solved the problem:

The crash seems to be the result of a floating point calculation that fails at some point. In my case, I had defined an aspect ratio of 16:9 or rather 9:16, which amounts to 0.5625. Changing the multiplier from 0.5625 to 0.5624 fixed the problem, no more crashes have appeared since then.

这篇关于iOS的纵横比约束的突破iOS7,适用于iOS8上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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