evnaz / ENSwiftSideMenu

A simple side menu for iOS written in Swift.
MIT License
1.82k stars 281 forks source link

Swipe from right with Objective C #66

Open yao23 opened 9 years ago

yao23 commented 9 years ago

Hi All,

  1. How to set up to allow side menu swipe from right side?
  2. I have swipe and pan gesture in my primary view (source view), how to disable swipe gesture for ENSwiftSideMenu in and out?

Thanks in advance.

evnaz commented 9 years ago

Hi, Try to set allowLeftSwipe and allowRightSwipe variables of the sideMenu to false

yao23 commented 9 years ago

Hi Evnaz,

  1. I changed the source code directly like:
    private var menuPosition:ENSideMenuPosition = .Right
    public var bouncingEnabled :Bool = false
    public var allowLeftSwipe : Bool = false
    public var allowRightSwipe : Bool = false

Left and right swipe are disabled, bouncing is disable neither, but why the side menu still slides from left instead of right? What should I do to make it slide from right side?

  1. Is it possible to customize the side menu height upon different page view, for example, there is bottom tool bar in home page, but other pages, so I want to make the side menu shorter in home page and longer in other pages?

Thanks.

yao23 commented 9 years ago

I solved the 1st problem with setting menuPosition as right in ENSideMenuNavigationController init method like this in ObjCExample:

    public init( menuTableViewController: UITableViewController, contentViewController: UIViewController?) {
        super.init(nibName: nil, bundle: nil)

        if (contentViewController != nil) {
            self.viewControllers = [contentViewController!]
        }

        sideMenu = ENSideMenu(sourceView: self.view, menuTableViewController: menuTableViewController, menuPosition:.Right)
        view.bringSubviewToFront(navigationBar)
    }

How about the 2nd question? How to set up different height based on different pages? User constraint for side menu to bottom view?

evnaz commented 9 years ago

If you use UITableView as a side menu view, you can set content insets:

tableView.contentInsets = UIEdgeInsetsMake(0, 0, toolBar.frame.size.height, 0)
yao23 commented 9 years ago

How can I disable the switch page view animation, because my side menu slide out from right, the current switching page is also from right side, so I wanna show it without animation, just let the current page disappear and next one appear. I tried to change

            UIView.animateWithDuration(0.1, animations: { () -> Void in
                self.sideMenuContainerView.frame = destFrame
            })

to

                self.sideMenuContainerView.frame = destFrame

in ENSideMenu::toggleMenu() method, but it still doesn't work.

yao23 commented 9 years ago

Hi Evnaz,

I update side menu table view part, add an variable currentIndex to get the current row in side menu, if clicked the side menu row whose page view is already open, then we close the side menu rather than load the page view again because we are already in the page. You can update it in the Objective C example.

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView setContentInset:UIEdgeInsetsMake(64.f, 0, 0, 0)];
    [self.tableView setBackgroundColor:[UIColor clearColor]];
    self.currentIndex = 0;
}

#pragma mark - UITableView Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.currentIndex == indexPath.row) {
        // close side menu
        [[self.sideMenuController sideMenu] toggleMenu];
        return;
    }

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *destTVC = nil;
    switch (indexPath.row) {
        case 0:
            destTVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
            break;
        default:
            destTVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
            break;
    }
    if (destTVC) {
        self.currentIndex = (int)indexPath.row;
        [self.sideMenuController setContentViewController:destTVC];
    } else {
        // close side menu
        [[self.sideMenuController sideMenu] toggleMenu];
    }
}
evnaz commented 9 years ago

To disable animation on switch view controllers set sideMenuAnimationType of navigation controller to None

navigationController.sideMenuAnimationType = .None
yao23 commented 9 years ago

How to initialize ENSideMenuNavigationController or ENSideMenu in a NavigationController or UIViewController class instead of assign it as root view controller in AppDelegate.m, because it's the not the 1st page in my case.

yao23 commented 9 years ago

I tried to create a new view controller and init in - (void)viewDidLoad() method like following,

MenuItemsTVC *sideMenuTVC = [MenuItemsTVC new];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *contentVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
ENSideMenuNavigationController *navVC = [[ENSideMenuNavigationController alloc] initWithMenuTableViewController:sideMenuTVC contentViewController:contentVC];
[self addChildViewController:navVC];
[navVC didMoveToParentViewController:self];
navVC.view.frame = self.view.frame;
[self.view addSubview:navVC.view];

It can shows the content view controller and side menu, the only part which doesn't work is that there is no response when click at the cell of side menu.

I log out the debug info when select the cell like:

#pragma mark - UITableView Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ NSLog(@"cur idx:%ld, index path row: %ld", (long)self.currentIndex, (long)indexPath.row);
    if (self.currentIndex == indexPath.row) {
        // close side menu
        [[self.sideMenuController sideMenu] toggleMenu];
        return;
    }

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *destTVC = nil;
    switch (indexPath.row) {
        case 0:
            destTVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
            break;
        default:
            destTVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
            break;
    }
    if (destTVC) {
        self.currentIndex = (int)indexPath.row;
        [self.sideMenuController setContentViewController:destTVC]; NSLog(@"cur vc: %@", destTVC.description); NSLog(@"vcs num: %lu", (unsigned long)self.navigationController.viewControllers.count);
    } else {
        // close side menu
        [[self.sideMenuController sideMenu] toggleMenu];
    }
}

and it shows: 2015-05-22 16:34:27.158 FS[15532:588753] cur idx:0, index path row: 0 2015-05-22 16:34:31.775 FS[15532:588753] cur idx:0, index path row: 1 2015-05-22 16:34:31.777 FS[15532:588753] cur vc: <ViewController: 0x7ffbd15334f0> 2015-05-22 16:34:31.777 FS[15532:588753] vcs num: 0 2015-05-22 16:34:43.673 FS[15532:588753] cur idx:1, index path row: 0 2015-05-22 16:34:43.674 FS[15532:588753] cur vc: <ViewController: 0x7ffbd32afc60> 2015-05-22 16:34:43.674 FS[15532:588753] vcs num: 0

it seems view controllers are not in navigation controller stack anymore.

yao23 commented 9 years ago

Is there any Objective C version published for this side menu?

evnaz commented 9 years ago

You can use this control in a ObjC project. ObjC example is in the repo.

yao23 commented 9 years ago

I tried integrate the side menu like OjbC example which is the very first controller and it works. But I added it in my current project flow which shows the first content page of side menu after user sign in, it can show and hide side menu and it can also log out the cell index number when click at the side menu row, but it cannot direct to the target page (view controller) like example. Is it because the side menu nav controller is not first entry and side menu not well configured?

I tried to create a new view controller and init in - (void)viewDidLoad() method like following:

MenuItemsTVC *sideMenuTVC = [MenuItemsTVC new];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *contentVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
ENSideMenuNavigationController *navVC = [[ENSideMenuNavigationController alloc] initWithMenuTableViewController:sideMenuTVC contentViewController:contentVC];
[self addChildViewController:navVC];
[navVC didMoveToParentViewController:self];
navVC.view.frame = self.view.frame;
[self.view addSubview:navVC.view];