8

Хорошо, так вот проблема я бегу в:переключения контроллеров просматривать с помощью салфетки жесты

Я пытаюсь перейти от одного viewController, что я назвал MenuViewController, который содержит мое меню (очевидно). У меня есть отдельный viewController с именем ViewController, который содержит мои mapView. Я хотел бы иметь возможность двойного пальца swipe left от моего MenuViewController до моего mapView.

Я не совсем уверен, с чего начать.

Кроме того, я использую файлы xib, а не раскадровку. Запуск iOS 6.

ответ

0

Прежде всего, вы не можете использовать встроенный механизм навигации.

Вам нужно будет добавить представление «ViewController» к представлению «MenuViewController», и я рекомендую вам добавить «ViewController» в качестве контроллера детского представления в «MenuViewController».

После этого установите рамку «ViewController» сбоку экрана, а когда вы проведете или сделаете свой жест, просто оживите его обратно на экран.

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  
     } 
    } 
} 
+0

Почему downvote ??? – Girish

+0

И это будет правильно входить в мой viewDidLoad? Что входит в мой заголовочный файл? Кроме того, как именно я буду «добавлять контроллер просмотра здесь»? –

+0

введите код жестов (первые 3 строки в моих ans) в viewDidLoad. Ничего в файле .h. Выделите свой контроллер и просто нажмите, добавьте или представите его в методе handleSwipeGesture. – Girish

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.. 
    } 

Надеюсь, это поможет вам ...

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]; 
     } 
    } 
} 
+0

А, безрезультатно, хороший сэр. Я загрузил его в свой заголовок и файл реализации. Я не уверен, правильно ли я делаю это, но на самом деле я использую API карт Google. Не отображает ли mapView непосредственно в ViewController по умолчанию? Однако я ценю ваши усилия. –

+0

замените свой код на строку ** [self.navigationController pushViewController: mapViewObj animated: YES]; ** – DharaParekh

+0

Прошу прощения, но я не следую. Что я должен заменить в этом разделе кода? –

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 для соответствующего толчка (слайда) навигации.

 Смежные вопросы

  • Нет связанных вопросов^_^