Подтвердить что ты не робот

Просмотры Навигация с использованием жестов

Как я могу переключать виды по вертикали, используя жестовые салфетки?

4b9b3361

Ответ 1

Я нашел свой ответ. Я отправляю код для справки. Спасибо: -)

in viewDidLoad

  UISwipeGestureRecognizer *swipeGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreendown:)] autorelease];
  swipeGesture.numberOfTouchesRequired = 1;
  swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
  [m_pImageView addGestureRecognizer:swipeGesture];

Теперь

- (void)swipedScreendown:(UISwipeGestureRecognizer*) swipeGesture {
  m_pViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
  CATransition *transition = [CATransition animation];
  transition.duration = 0.75;
  transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  transition.type = kCATransitionPush;
  transition.subtype = kCATransitionFromBottom;
  transition.delegate = self;
  [self.view.layer addAnimation:transition forKey:nil];
  [self.view addSubview:PadViewController.view];
}

Если вам нужно уточнить, пожалуйста, напишите здесь.

Ответ 2

Внедрите это (didload)

//........towards right Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[urView addGestureRecognizer:rightRecognizer];
[rightRecognizer release];

//........towards left Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[urView addGestureRecognizer:leftRecognizer];
[leftRecognizer release];   

Затем:

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer 
{
//Do moving
}

- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer 
{
// do moving
}

Ответ 3

Конечно! Просто установите свой viewController как UIGestureRecognizerDelegate и объявите UISwipeGestureRecognizer *swipeLeftRecognizer; (также сохраните и синтезируйте). Затем, в реализации, настройте распознаватели с помощью

    UIGestureRecognizer *recognizer;
    // RIGHT SWIPE
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                           action:@selector(handleSwipeFrom:)];
    [self.view addGestureRecognizer:recognizer];
    [recognizer release];
    // LEFT SWIPE
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    self.swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeLeftRecognizer];
self.swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
    [recognizer release];

Затем выполните действия, которые вы хотите, с помощью метода

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
        // load a different viewController
    } else {
        // load an even different viewController
    }
}

Что вы здесь делаете конкретно для своего приложения. Вы можете переключить выбор tabBar, перейти через navigationController, представить другой вид в моделях или просто сделать простой переход в процессе перехода.

Ответ 4

Добавление жестов в быстрые

func addSwipes() {
    // Left Swipe
    let swipeLeft = UISwipeGestureRecognizer(target: self, action: "swipeLeft:")
    swipeLeft.direction = .Left
    self.view.addGestureRecognizer(swipeLeft)

    // Right Swipe
    let swipeRight = UISwipeGestureRecognizer(target: self, action: "swipeRight:")
    swipeRight.direction = .Right
    self.view.addGestureRecognizer(swipeRight)
}

func swipeLeft(gestureRecognizer: UISwipeGestureRecognizer) {
}

func swipeRight(gestureRecognizer: UISwipeGestureRecognizer) {

}

Ответ 5

Для справки PengOne, вот код, на который вы ссылались в своем комментарии выше. Я сохранил его на своем Mac, потому что думал, что это может быть полезно в один прекрасный день...: D

// Manual navigation push animation
UIImage* image = [UIImage imageNamed:@"CurrentView"];
UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = self.view.bounds;
[self.view addSubview:imageView];
[imageView release];
CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.layer addAnimation:transition forKey:@"push-transition"];