简体   繁体   中英

iOS 7 vs iOS 8 autoloayout issues

I cannot solve autolayout issues for iOS 7. Please look at the screen shots.

  1. iOS 8 screen shot. No problems, everything looks as it should and works ok.

iOS 8屏幕截图

  1. iOS 7 screen shot. Notice UI artifacts. What is weird is that they are not the same every time I run the app. And when they happen they of course mess with the app responsiveness, etc.

iOS 7屏幕截图与工件

  1. And always when this happens I get the same autolayout error. Always something with _UILayoutGuide. I tried everything but could not solve this issue. NOTE: on iOS 8 I do not have a slightest problem.

自动布局错误

I've reworked whole UI (from zero) with autolayout >20 times. And never there is a problem with running the app on iOS8, always on iOS 7 with the same error as mentioned above. All the UI and constraints are done inside interface builder (storyboard). All of the buttons are UIViews containing UILabels and that's it.

Any ideas what to try next?

EDIT: Copy/Paste message here:

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.

EDIT 2:

After I examined everything more precisely I've noticed the issue is UIView which contains OK/Circle (and V+/V-/P+/P- buttons) button. If I remove every button in this UIView there is no more autolayout exception. That's as far as I could get till now...

EDIT 3:

After further digging into the problem I found something else that could be a problem. Look at the code below (when user hits one of the two bottom-bar buttons, this happens):

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
        })
    }

It looks like autolayout becomes broken after changing the frame of the view (in my case there are 2 container views inside that root-view).

Your constraints are overdetermined. I don't know why this issue doesn't emerge on iOS 8, but it is plain to see in the list of constraints in your screen shot what the problem is. In order, we have (I'll use the last two digits of the memory address of the views to identify them):

  • The top of view 80 -

     V:|-(0)-[UIView:0x7b099c80] 
  • The height of view 80 -

     UIView:0x7b099c80.height == ... 
  • The space between the bottom of view 80 and the top of view 60 -

     V:[UIView:0x7b099c80]-(0)-[UIView:0x7b099260]> 
  • The height of view 60 -

     UIView:0x7b099260.height == ... 
  • The bottom of view 60 -

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

That's too many constraints. You can set the top and the height or the top and the bottom of something, but you must not set the top and the height and the bottom - because if the resulting arithmetic is off by even a tiny bit, those demands cannot be satisfied simultaneously.

OMG finally it looks like the problem is this:

iOS aspect ratio constraint breaks on iOS7, works on iOS8

That is - some combination of aspect-ratios + equal (heights, etc) are broken on iOS7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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