dekatotoro / SlideMenuControllerSwift

iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.
MIT License
3.4k stars 755 forks source link

strange layout change with SideMenuController and switching between apps #192

Open TripwireNL opened 8 years ago

TripwireNL commented 8 years ago

Hi,

I've encountered a weird behavior when using this controller. Consider the following:

  1. open the sidemenu (mine is on the right)
  2. double tap home button
  3. switch to another app
  4. double tap the home button again
  5. switch back to the app with the sidemenucontroller

When I do this in my app the whole app seems change layout and moves a few pixels to the side. This only happens when switching apps with the sidemenu open. Any idea what could cause this problem? If screenshots are needed, i'll add some later (and maybe a video to).

katanagari7c1 commented 8 years ago

I've reproduced the same behavior just by loading an image asynchronously in the side bar when it is about to appear (leftWillOpen in my case)

eseason commented 8 years ago

Also reproduced, just updating the text on a label in the menu (left) view and everything shifts down and to the right.

It shifts right by 8 and down by 20 - those number seem to line up with "standard value" and the standard margin

mbragg1 commented 7 years ago

I was able to reproduce the issue by programmatically calling openLeft(). I am using Swift 2.2 and have not tried this on any newer Swift version. This seems to be an iOS bug related to AutoLayout/Container management. My observations:

  1. I was able to avoid the UI issue by commenting out all the calls leftViewController?.beginAppearanceTransition() in SlideMenuController.swift. This however causes the child VCs to not receive viewWillAppear(), viewDidAppear() calls from the container VC. None of my code in viewWillAppear() touches the UI.
  2. I could fix the x-offset issue by changing my constraints. I aligned a UI element of my view to the Horizontal Center of the container, and then used Equal widths to the container (instead of using leading edge and trailing edge constraints to the container). However the y-offset bug was still there, which seems to be related to using constraints against the TopLayoutGuide.
  3. I was able to avoid the issue completely by putting my view inside a parent view in IB. The parent view has constraints for EqualWidth, EqualHeight, CenterVertically, CenterHorizontally to the container (not LeadingEdge or TopLayoutGuide). The child view has constraints against Superview, which seems to work fine.

If anyone has this issue on Swift 3 and verifies this fixes the issue there as well, we should open a Radar with Apple, otherwise it may already be fixed in Swift 3.

morteg commented 7 years ago

mbragg1, thank you very much, your comment helped me to fix a bug with y aligment of menu. I'm just changed my menu constrains to your's from №3. It seems to be a bug with TopLayoutGuide constrain.

P.S I'm using xcode 8.1 and swift 3.0

meta-arpit-pittie commented 7 years ago

@mbragg1 I have implemented your solution No. 3 regarding the y constraint. And it worked for me as well. I was doing the same putting all views inside a parent view with constraints top, bottom, leading and trailing for the parent view. But they were of no use. I replaced my constraints with the one you mentioned, and now its resolved.

P.S using swift 3.1 and xcode 8.3.3