簡體   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