Code Monkey home page Code Monkey logo

kwdrawercontroller's Introduction

KWDrawerController

Pod Version Pod Platform Pod License Swift

Drawer view controller that is easy to use!

Installation

CocoaPods (iOS 8+ projects)

KWDrawerController is available on CocoaPods. Add the following to your Podfile:

# Swift 3
pod 'KWDrawerController', '~> 3.7'

# Swift 4~
pod 'KWDrawerController', '~> 4.2'
pod 'KWDrawerController/RxSwift'        # with RxSwift extension

Manually

Simply drag and drop the DrawerController folder into your existing project.

Usage

Code

import UIKit

import KWDrawerController

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        let mainViewController   = MainViewController()
        let leftViewController   = LeftViewController()
        let rightViewController  = RightViewController()
        
        let drawerController     = DrawerController()

        drawerController.setViewController(mainViewController, .none)
        drawerController.setViewController(leftViewController, .left)
        drawerController.setViewController(rightViewController, .right)

        /// Customizing

        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.rootViewController = drawerController
        window?.makeKeyAndVisible()

        return true
    }
}

Storyboard

Storyboard

  1. Set DrawerController as the Custom Class of the Initial ViewController.

  2. Connect the DrawerEmbedLeftControllerSegue and/or the DrawerEmbedRightControllerSegue from DrawerController to your left/right controllers.

  3. Connect the DrawerEmbedMainControllerSegue from DrawerController to your main controller.

  4. Set the segue identifiers of both the inspector of DrawerController and the segues themselves.

Open / Close

/// Open
self.drawerController?.openSide(.left)
self.drawerController?.openSide(.right)

/// Close
self.drawerController?.closeSide()

Delegate

optional func drawerDidAnimation(
    drawerController: DrawerController,
    side: DrawerSide,
    percentage: Float
)

optional func drawerDidBeganAnimation(
    drawerController: DrawerController,
    side: DrawerSide
)

optional func drawerWillFinishAnimation(
    drawerController: DrawerController,
    side: DrawerSide
)

optional func drawerWillCancelAnimation(
    drawerController: DrawerController,
    side: DrawerSide
)

optional func drawerDidFinishAnimation(
    drawerController: DrawerController,
    side: DrawerSide
)

optional func drawerDidCancelAnimation(
    drawerController: DrawerController,
    side: DrawerSide
)

Customizing

Transition

DrawerTransition is a module that determines the rendering direction to move the Drawer. It is implemented by inheriting DrawerTransition.

  • DrawerSlideTransition

DrawerSlideTransition

  • DrawerScaleTransition
    • Use is not recommended.
  • DrawerParallaxTransition

DrawerParallaxTransition

  • DrawerFloatTransition
    • When using the Transition, Overflow Transition should also use DrawerFloatTransition.

DrawerFloatTransition

  • DrawerFoldTransition

DrawerFoldTransition

  • DrawerSwingTransition

DrawerSwingTransition

  • DrawerZoomTransition

DrawerZoomTransition

Overflow Transition

Overflow Transition be used when Transition beyond the open range of the drawer.

  • DrawerSlideTransition
  • DrawerScaleTransition
    • This is natural when used with DrawerSlideTransition, DrwaerParallaxTransition, DrawerFoldTransition, and DrawerSwingTransition.

DrawerScaleTransition

  • DrawerParallaxTransition
  • DrawerFloatTransition
    • When using the Overflow Transition, Transition should also use DrawerFloatTransition.
  • DrawerFoldTransition
    • Use is not recommended.
  • DrawerSwingTransition
    • Use is not recommended.
  • DrawerZoomTransition

Animator

Animator is a module that controls the speed of moving a drawer. It is implemented by inheriting DrawerAnimator or DrawerTickAnimator.

  • DrawerLinearAnimator
  • DrawerCurveEaseAnimator
  • DrawerSpringAnimator
  • DrawerCubicEaseAnimator
  • DrawerQuadEaseAnimator
  • DrawerQuartEaseAnimator
  • DrawerQuintEaseAnimator
  • DrawerCircEaseAnimator
  • DrawerExpoEaseAnimator
  • DrawerSineEaseAnimator
  • DrawerElasticEaseAnimator
  • DrawerBackEaseAnimator
  • DrawerBounceEaseAnimator

Options

public var isTapToClose: Bool
public var isGesture: Bool
public var isAnimation: Bool
public var isOverflowAnimation: Bool
public var isShadow: Bool
public var isFadeScreen: Bool
public var isBlur: Bool
public var isEnable: Bool

Changelog

  • 1.0 First Release.
  • 1.1 Bug Fix, Add animations.
  • 2.0 Refactoring.
  • 2.1 Bug Fix, Update animation.
  • 2.2 Fix animation, and some bugs.
  • 3.0 Written in Swift 3.0
  • 3.1 Fix Access Control issues on DrawerController.
  • 3.2 Fix Access Control issues on Transition.
  • 3.3 Fix Access Control issues on initializer.
  • 3.4 Remove debug log.
  • 3.5 Fixed bug where touch ignores is not applied for "Absolute Controller".
  • 3.6 Fixed an occurs issue while the drawer was open and layout changing.
  • 3.6.1 Fixed layout issue when rotate device.
  • 3.7 Fixed not updating issues on properties.
  • 4.0 Support Swift 4.
  • 4.1 Implement new flag that enables direction auto-switching.
  • 4.1.1 Support RxSwift(If you want).
  • 4.1.2
    • Fix issues on auto layout of child view controllers.
    • Replace naming.
    • Implement getViewController method.
    • Reduce cloning size.
  • 4.1.3
    • Fix crashed on load. (#12)
  • 4.1.4
    • Add state methods to delegate. (#16)
    • Fix access control issues. (#18)
    • Fixed DrawerFloatTransition bug. (#20)
    • DrawerController incorrectly manages lifecycles of child controllers. (#21 #22)
  • 4.1.5
    • Code and performance improvements and bug fixes. (#24 @rivera-ernesto)
  • 4.1.6
    • Fix transition bugs.
    • Fix gesture not working bugs.
    • Fix right drawer placement on iPads (#28 @rivera-ernesto)
  • 4.2
    • Support swift 4.2. (#31)

⚠️ Requirements

  • iOS 8.0+
  • Swift 3.0+

🔑 License

KWDrawerController is under MIT license. See the LICENSE file for more info.

kwdrawercontroller's People

Contributors

0xch4z avatar kawoou avatar rivera-ernesto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kwdrawercontroller's Issues

애니메이션 추가 구현

  • (KWDrawerAnimationBlock)foldingAnimationBlock;
  • (KWDrawerAnimationBlock)swingingDoorAnimationBlock;
  • (KWDrawerAnimationBlock)parallaxAnimationBlock:(CGFloat)parallaxFactor;

preferredStatusBarStyle

Hi there,

After some tests I realized that preferredStatusBarStyle and similar where not set from the currently displayed side, it would be nice to forward them and ask the system for a status bar update when opening/closing a side.

Would you like a PR?

Thanks again,

Stan

Remove the gestures for a certain drawer

How do I remove the gestures for a certain drawer?

I will have a drawer with the main menu on all pages, and a drawer with an module submenu for a certain module...

and I want only the main menu to be triggered by gestures...

Slide animation bug

Hi, I am seeing a random bug that is reproducible only on a device (tested on iPhone 5S and 7)
I am using your example, without any modifications. The issue is that sometimes, when I press the button to open the right drawer (transition is set to Slide), the drawer opens up fine, but sometimes the slide animation stutters and the side viewcontroller is offset to the left of the screen (notice that the main viewcontroller underneath it remains at its initial position)

right
wrong

Set status bar style

Now default status bar style (black) is used for DrawerController . To change the style, I have to write something like that:

extension DrawerController {
 open override var preferredStatusBarStyle: UIStatusBarStyle {
  return UIStatusBarStyle.lightContent
 }
}

Please add possibility to set status bar style via initializer or property of DrawerController class. And it would be great to get default status bar style (if it hasn't been set explicitly) as status bar style of content controller.

Observe state with delegate

Thanks for the library! It would be cool if there was a delegate protocol to preform actions on the drawer state changing rather than having to pass a completion handler in. For example, the following stubs:

func drawerController?(willOpenSide side: DrawerSide)

func drawerController?(willCloseSide side: DrawerSide)

I'd be happy to submit a PR.

Thanks,
Charles

Using a .right side menu, at first attempt of openSide(.right) results in a left side opening

With any gesture or touch after this misplacement, problem will resolve and .right side opens properly.
I tried to debug very hard to contribute the project, yet I could not solve the puzzle.
My guess: there might be an invalide size/frame reading occur before the (.right)view became visible.
Thank you for opensourcing this project I was using it for over a year without any issues, then the specs changed and customer wants a right hand side menu:)

Cheers,

Width of side menu as percentage

Now I can set drawer width only in points. Because of that, side menu doesn't adapt to changes of size width. For example, I can't make menu occupying one third of screen without writing custom code that will update menu width when size of screen changes.
It would be useful to specify side menu width as percentage of screen width. Maybe can you suggest some way to use Auto Layout for side menu size determination?

Unknown class KWDrawerController in Interface Builder file.

First of all thanks for the great library.

I am having an issue, when i set Custom Class to "KWDrawerController" via story board there is no build issue only the console show this message "Unknown class KWDrawerController in Interface Builder file."

I have removed the libs via pods and installed many times but still the same issue.

Hoping for quick response.

Thanks.

DrawerController incorrectly manages lifecycles of child controllers

Please see attached project. I have initial view controller with button "Go". When I press this button, I initialize DrawerController, set SideMenuController as side menu and InnerContentController as content, and set DrawerController as root window controller. Pressing "Go button" produces console output:

inner content controller will disappear
inner content controller did disappear
inner content controller will appear
side menu controller will appear
inner content controller did appear
side menu controller did appear

But InnerContentController has never disappeared of course. And SideMenuController has never appeared. The console output should be as follows:

inner content controller will appear
inner content controller did appear

So, lifecycles of child controllers are managed by DrawerController incorrectly. I have a much bigger application, and in this application method viewDidAppear of some controller inside DrawerController isn't getting called. Because of that, my important code in this method is not executed. Without DrawerController, all works fine.

Please fix this, it is the critical problem.

drawertest.zip

Use in Objective-C project

Hi Kawoou,

I'm using your framework through CocoaPods, I use it exactly as your instruction, but storyboard failed to init DrawerController and returns a plain UIViewController as the initial ViewController. Do you happen to know what's the issue here? Thank you so much in advance!

2018-01-16 6 26 29

2018-01-16 6 26 35

2018-01-16 6 26 43

2018-01-16 6 26 48

Unable to get delegates to fire

Is there an example of using the delegates somewhere? I'm having trouble getting any delegate method to fire, and I badly need to be able to respond to drawer state as it changes.

not working after pod install

I installed it with pod ,used it with storyboard, it was not working, it displayed with DrawViewcontroller only.
# Swift 4~ pod 'KWDrawerController', '~> 4.2' pod 'KWDrawerController/RxSwift' # with RxSwift extension

But when I remove 'KWDrawerController' from podfile and drag the DrawerController folder to my project, it working well.

Did i missed sth?

I can't trigger to open left or right side by button action.

I followed instructions for storyboard and I set controllers correctly.

class Example: UIViewController, DrawerControllerDelegate {

override func viewDidLoad()  {
        super.viewDidLoad()
        self.drawerController?.delegate = self
        self.drawerController?.options.isAnimation = false
        self.drawerController?.setTransition(DrawerFloatTransition(), for: .left)
}

When I try to trigger open left side with this code block, drawerController throws nil error and crash.

if self.drawerController!.drawerSide == .none {
            self.drawerController?.openSide(.left)
                .subscribe()
                .disposed(by: disposeBag)
        } else {
            self.drawerController?.closeSide()
                .subscribe()
                .disposed(by: disposeBag)
        }

Not working

No idea about how to implement KWDrawerController. And it is not working and it produces a black screen

Crashed on load

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<KWDrawerController.DrawerController: 0x7f9e23978a00>)

screen shot 2018-01-29 at 2 01 48 am

Need Info

When embedded in navigationController to drawerController , drawerController height is bottom of the navigation bar . Can i know how to overlap for navigation bar for drawercontroller ?

Allow DrawerTransition subclass

Hello,

I just discovered this project and find it very interesting, and very well done. However I'd like to implement a custom transition (sliding left side, with fixed center VC masked by shadow + semi-opaque color), which is not currently possible because the base class is not defined as public.

Would it be possible to declare it public? Also if you think there will be an issue with implementing the transition I'm looking for and have a quick fix that would be very appreciated; if you don't have the time I can send a PR your way when I've had the chance to try.

Thanks a lot for your time,

Stan

Using DrawerSlideTransition should resize the side view controllers to the available width

First off, really good work, it's a really clear project and easy to setup!

I have a suggestion: when using a DrawerSlideTransition, since no background is visible (like DrawerFloatTransition for instance), it would be great if the child view controllers were resized to fit the available width.

I have been able to make this by updating a bit DrawerContent.swift :

    internal func updateView() {
        let width = CGFloat(drawerWidth)
        contentView.frame.size.width = width
        drawerOffset = 0.0
        
        guard let superView = contentView.superview else { return }
        if drawerSide == .right {
            drawerOffset = superView.frame.width - width
        }
        viewController.view.frame = CGRect(
            x: 0,
            y: 0,
            width: width,
            height: superView.frame.height
        )
    }

This may not be perfect to obtain the needed behaviour, and this affects all other transitions. Would you know a way to achieve this behaviour with a custom transition or a an additional setting?

I also noticed it's not possible de create custom transitions because the methods of DrawerTransition are not marked open.

pod install issue

i can't install this framework with below message...

[!] Unable to satisfy the following requirements:

  • KWDrawerController (~> 3.6.1) required by Podfile

None of your spec sources contain a spec satisfying the dependency: KWDrawerController (~> 3.6.1).

You have either:

  • out-of-date source repos which you can update with pod repo update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

so i tried to install with 'pod 'KWDrawerController'' but pod tried install 3.3 version.

Orientation Change Bug

When maiViewController (Child of KWDrawer) is rotate when viewDidLoad() of maiViewController is call again?

When closing a side panel presented using DrawerFloatTransition, the primary view is sometimes re-presented offset to the left

When closing a side panel that has been presented using a DrawerFloatTransition, the main view controller is not always restored properly and is instead drawn offset to the left by approximately 30 pixels. This creates a visual defect in the UI. Subsequent open / close of the side panel will exacerbate the situation, eventually causing the primary view to become unusable.

See images below:

one
two
three

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.