KYDrawerController icon indicating copy to clipboard operation
KYDrawerController copied to clipboard

On first display, drawer controller animates vertically

Open ColdLogical opened this issue 7 years ago • 8 comments

On first run of

drawerController.setDrawerState(KYDrawerController.DrawerState.Opened, animated: true)

to open the drawer, the drawer view controller has a slight vertical animation. Presumably, this is from a CGRectZero frame or something similar. Calls to drawerController.drawerViewController?.loadView() or drawerController.drawerViewController?.view.layoutIfNeeded() before display have no effect.

Current workaround is to open and close the drawer without an animation after application has finished launching.

drawerController.setDrawerState(KYDrawerController.DrawerState.Opened, animated: false)
drawerController.setDrawerState(KYDrawerController.DrawerState.Closed, animated: false)

but creates warnings in the debugger

Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7ff262ed9870>.
Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7ff26305f600>.

ColdLogical avatar Aug 10 '16 19:08 ColdLogical

i got the same issues. But i guess i managed to solve it by setting Top Bar = Opaque Navigation Bar

kohdesmond avatar Aug 23 '16 09:08 kohdesmond

@kohdesmond what do you mean set top bar? On which controller?

ColdLogical avatar Aug 24 '16 15:08 ColdLogical

@ColdLogical on the storyboard screen shot 2016-10-10 at 15 12 28

kohdesmond avatar Oct 10 '16 07:10 kohdesmond

@kohdesmond Do you mean 'simulated metrics'? How can it affect for the running app?

psi-gh avatar Nov 07 '16 11:11 psi-gh

@psi-gh not quite sure but the simulated metrics affected my auto layout. but it seems to only affect iOS 10 and it might be a "feature" with xcode 8

@ColdLogical does the weird fix works for you?

kohdesmond avatar Nov 29 '16 06:11 kohdesmond

+1

I have encountered the same issue.

Does anyone know how to fix it?

Fogrunner avatar Jan 10 '18 14:01 Fogrunner

As ColdLogical mentioned, we can avoid awkward moving by calling below

drawerController.setDrawerState(KYDrawerController.DrawerState.Opened, animated: false)
drawerController.setDrawerState(KYDrawerController.DrawerState.Closed, animated: false)

However, we could see warning also.

To avoid this.

Chage code a little bit

public func setDrawerState(_ state: DrawerState, animated: Bool) {
...

to

public func setDrawerState(_ state: DrawerState, animated: Bool, completion : (() -> ())? = nil) {
..
    { (finished: Bool) -> Void in
       ..
       completion?() 
    }

And then call like this.

 setDrawerState(KYDrawerController.DrawerState.opened, animated: false)
 {
     self.setDrawerState(KYDrawerController.DrawerState.closed, animated: false
 }

You can avoid the warning.

Fogrunner avatar Jan 10 '18 14:01 Fogrunner

Note, calling:

drawerController.setDrawerState(KYDrawerController.DrawerState.Opened, animated: false)
drawerController.setDrawerState(KYDrawerController.DrawerState.Closed, animated: false)

Can cause an imbalance of calls to beginAppearanceTransition/endAppearanceTransition which can cause your app to stop presenting view controllers correctly.

Customising the KYDrawerController to include a completion handler to 'resolve warnings' as suggested above helps to some degree (doesn't guarantee a balance of above mentioned calls).

The whole idea of opening and closing the drawer with no animation to fix a layout issue is a total hack.

@ykyouhei can you please look into this issue?

timusus avatar May 24 '18 03:05 timusus