ykyouhei / KYDrawerController

Side Drawer Navigation Controller similar to Android
MIT License
621 stars 158 forks source link

On first display, drawer controller animates vertically #61

Open ColdLogical opened 8 years ago

ColdLogical commented 8 years ago

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>.
kohdesmond commented 8 years ago

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

ColdLogical commented 8 years ago

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

kohdesmond commented 8 years ago

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

psi-gh commented 8 years ago

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

kohdesmond commented 7 years ago

@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?

Fogrunner commented 6 years ago

+1

I have encountered the same issue.

Does anyone know how to fix it?

Fogrunner commented 6 years ago

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.

timusus commented 6 years ago

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?