What's the best way to develop a sideswipe men

2019-01-01 06:03发布

It appears that side-swipe menus are becoming a more common interface element as more information gets crammed into each iPhone app. Facebook has included it in their latest version and the new Gmail app appears to include it as well. I was wondering if anybody had thoughts on the most efficient way of developing something like this as it's becoming a more common interface element. While I have my own thoughts on how to build this, I'm curious to hear what other people think.

Facebook swipe navigation

18条回答
无与为乐者.
2楼-- · 2019-01-01 06:46

I recently came across this, didn't actually look at the code or test the control, but looks like it may be a very decent starting point.

jtrevealsidebar

Edit: The reader should also take a look at the other answers :)

查看更多
美炸的是我
3楼-- · 2019-01-01 06:46
几人难应
4楼-- · 2019-01-01 06:47

The key idea that you have to set self.navigationController.view's frame or center. There is two event that you have to handle. (1) barButtonItem press. (2) pan gesture because of swiping.

You can send view controller to the background like this:

[self.view sendSubviewToBack:menuViewController.view];

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonPressed:)];
    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
    [self.navigationController.view addGestureRecognizer:panGestureRecognizer];
    self.navigationItem.leftBarButtonItem = barButtonItem;
}

- (void)buttonPressed:(id)sender {

    CGRect destination = self.navigationController.view.frame;

    if (destination.origin.x > 0) {
        destination.origin.x = 0;
    } else {
        destination.origin.x = 320;
    }

    [UIView animateWithDuration:0.25 animations:^{
        self.navigationController.view.frame = destination;
    }];
}

- (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
    static CGPoint originalCenter;

    if (recognizer.state == UIGestureRecognizerStateBegan)
    {
        originalCenter = recognizer.view.center;

    } else if (recognizer.state == UIGestureRecognizerStateChanged)
    {
        CGPoint translation = [recognizer translationInView:self.view];

        recognizer.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y);
    }
    else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed)
    {
        if (recognizer.view.frame.origin.x < 160) {
            [UIView animateWithDuration:0.25 animations:^{
                recognizer.view.center = CGPointMake(384, 487.5);
            }];
        } else {
            [UIView animateWithDuration:0.25 animations:^{
                recognizer.view.center = CGPointMake(384 + 320, 487.5);
            }];
        }
    }
}
查看更多
浅入江南
5楼-- · 2019-01-01 06:48

Check out MMDrawerController:

MMDrawerController

We couldn't find a library that we liked, so we just rolled our own.

查看更多
大哥的爱人
6楼-- · 2019-01-01 06:48

the view in the right could be inside a subclass of UIScrollView. In this subclass you can override - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event to return YES only if the user touched the subview. This way you can place your transparent UIScrollView over any other view and pass through any touch event that takes place outside the subview; and you get scroll stuff for free.

For example:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    CGPoint location=[self convertPoint:point toView:subview];
    return (location.x > 0 && 
            location.x < subview.frame.size.width && 
            location.y > 0 && 
            location.y < subview.frame.size.height);
}

or:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    return [subview pointInside:
             [self convertPoint:point toView:subview] withEvent:event];
查看更多
时光乱了年华
7楼-- · 2019-01-01 06:53

this is exactly the clone of the facebook sidebar : GHSidebarNav library

very easy to use. instruction are in

查看更多
登录 后发表回答