iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

PBRevealViewController

Version License Platform

A slide UIViewController subclass for revealing a side (left and/or right) view controller above or below a main view controller for iOS and tvOS, inspired on SWRevealViewController subclass.

PBRevealViewController is compatible with both iOS and tvOS, and currently works with Swift 5.0, Swift 4.2 (swift-4.2 branch) and Objective-C!

Examples

Image Image Image Image

Installation

To run the example projects, clone the repo, and run pod install in your Terminal from the Example directory first.

You can also run pod try PBRevealViewController in your Terminal from anywhere.

Swift Package Manager

PBRevealViewController supports SPM versions 5.1.0 and above. To use SPM, you should use Xcode 11 or above to open your project. Click File -> Swift Packages -> Add Package Dependency, enter https://github.com/iDevelopper/PBRevealViewController. Select the version you’d like to use.

Manual

The easiest way to install it is by copying the following to your project:

Or

CocoaPods

PBRevealViewController is also available through CocoaPods.

To install the library to your project:

PBRevealViewController has subspecs for both Objective-C and Swift! Currently, Objective-C is the default subspec.

That means to use PBRevealViewController in an Objective-C project, add the following to your project's Podfile:

pod 'PBRevealViewController'

But if you're using Swift, add the following instead to specify the Swift subspec:

pod 'PBRevealViewController/Swift'

Features

Requirements

Usage

New: See panFromLeftBorderWidth and panFromRightBorderWidth properties!

Objective-C:

- (BOOL)revealControllerPanGestureShouldBegin:(PBRevealViewController *)revealController direction:(PBRevealControllerPanDirection)direction
{
    CGPoint point = [revealController.panGestureRecognizer locationInView:self.view];
    if (!revealController.isLeftViewOpen && direction == PBRevealControllerPanDirectionRight && point.x < 50.0) {
        return YES;
    }
    if (!revealController.isRightViewOpen && direction == PBRevealControllerPanDirectionLeft && point.x > (self.view.bounds.size.width - 50)) {
        return YES;
    }
    if (revealController.isLeftViewOpen || revealController.isRightViewOpen) {
        return YES;
    }
    return NO;
}

Swift 3:

    func revealControllerPanGestureShouldBegin(_ revealController: PBRevealViewController!, direction: PBRevealControllerPanDirection) -> Bool {
        let point = revealController.panGestureRecognizer.location(in: view)
        if !revealController.isLeftViewOpen && direction == .right && point.x < 50.0 {
            return true
        }
        if !revealController.isRightViewOpen && direction == .left && point.x > (view.bounds.size.width - 50) {
            return true
        }
        if revealController.isLeftViewOpen || revealController.isRightViewOpen {
            return true
        }
        return false
    }

Basic API Description

Image

Special Mention

A Special Thank to Joan Lluch.

This code was inspired on her excellent and similar class SWRevealViewController.

Author

iDevelopper, patrick.bodet4@wanadoo.fr

License

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

Please tell me when you use this controller in your project!

Regards,

Patrick Bodet aka iDevelopper