8

好的,这是我遇到的问题:

我正在尝试从viewController我命名MenuViewController的包含我的菜单的菜单(显然)切换。我有一个单独的viewController名称ViewController,其中包含我的mapView. 我希望能够swipe left从我MenuViewController的双指到我的mapView

我不确定从哪里开始。

另外,我使用的是 xib 文件,而不是情节提要。运行 iOS 6。

4

6 回答 6

13
UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
[self.view addGestureRecognizer:swipeLeftGesture];
swipeLeftGesture.direction=UISwipeGestureRecognizerDirectionLeft;

-(void)handleSwipeGesture:(UIGestureRecognizer *) sender
{
    NSUInteger touches = sender.numberOfTouches;
    if (touches == 2)
    {
        if (sender.state == UIGestureRecognizerStateEnded)
        { 
            //Add view controller here    
        }
    }  
}
于 2013-06-26T06:15:33.087 回答
4

一旦经历了这些,

UISwipeGestureRecognizer  *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleleftSwipe:)];
swipeLeft.numberOfTouchesRequired = 1;//give required num of touches here ..
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = (id)self;
[self. view addGestureRecognizer:swipeLeft];

UISwipeGestureRecognizer  *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlerightSwipe:)];
swipeRight.numberOfTouchesRequired = 1;//give required num of touches here ..
swipeRight.delegate = (id)self;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];

现在定义如下滑动方法:

 -(void)handleleftSwipe:(UISwipeGestureRecognizer *)recognizer{
//Do ur code for Push/pop..
  }
-(void)handlerightSwipe:(UISwipeGestureRecognizer *)recognizer{
 //Do ur code for Push/pop..
  }

希望对你有帮助...

于 2013-06-26T06:24:59.677 回答
1

尝试这个...

在 .h 文件中

@interface MenuViewController : UIViewController {
    ViewController *mapViewObj;
}

在 .m 文件中

-(void) viewDidLoad {
    [super viewDidLoad];

    mapViewObj = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    [self.view addGestureRecognizer:swipeLeftGesture];
    swipeLeftGesture.direction=UISwipeGestureRecognizerDirectionLeft;
}

-(void)handleSwipeGesture:(UIGestureRecognizer *) sender {
    NSUInteger touches = sender.numberOfTouches;
    if (touches == 2)     {
        if (sender.state == UIGestureRecognizerStateEnded)    {
            //push mapViewObj over here..
            [self.navigationController pushViewController:mapViewObj animated:YES];
        }
    }  
}
于 2013-06-26T06:28:34.400 回答
1

这是我为你编码的。

//add gesture recogniser to your view
[self addSwipegestureToView:self.view];


- (void) addSwipegestureToView : (UIView *) view{
    UISwipeGestureRecognizer *_swipegestureRecogniser = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesturePerformed)];
    _swipegestureRecogniser.numberOfTouchesRequired = 2;
    [_swipegestureRecogniser setDirection:UISwipeGestureRecognizerDirectionLeft];
    [view addGestureRecognizer:_swipegestureRecogniser];
}

- (void) swipeGesturePerformed{
    SecondViewController *object = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:object animated:YES];
}

你只需要拥有, currentViewController必须拥有navigationController适当的推送(滑入)导航。

于 2013-06-26T06:55:55.820 回答
0

这听起来像是使用UIGestureRecognizer或更具体地说是UISwipeGestureRecognizer的最佳时机

于 2013-06-26T06:21:18.087 回答
0

首先,您不能使用内置的导航机制。

您需要将“ViewController”的视图添加到“MenuViewController”的视图中,我建议您将“ViewController”作为子视图控制器添加到“MenuViewController”。

之后,将“ViewController”的框架设置在屏幕之外,当您滑动或做手势时,只需将其动画化回屏幕即可。

于 2013-06-26T06:14:25.393 回答