【问题标题】:UITabBarController, any possible way to move next View Controller with horizontal swipe?UITabBarController,任何可能的方式来移动下一个视图控制器与水平滑动?
【发布时间】:2012-12-04 10:20:21
【问题描述】:

我是 iOS 新手。不确定是否有可能带来以下逻辑。

1. UITabBarController has three UIViewController.
2. While Swipping horizontally in the second UIViewController, i want to move
   to the third UIViewController. 

有可能吗?如果是这样,请建议如何实现相同的目标。

【问题讨论】:

    标签: iphone objective-c ios ios4


    【解决方案1】:

    在第二个 ViewController 中,在 ViewDidLoad 中添加以下行

    UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gotoNextPage:)];
    [self.view addGestureRecognizer:swipeRecognizer];
    [swipeRecognizer release];
    

    并添加方法

    -(void)gotoNextPage:(id)sender {
        [self.tabBarController setSelectedViewController:thirdViewController];
    }
    

    【讨论】:

    • 你能试试下面的代码吗? for(UIViewController *viewController in self.tabBarController.viewControllers) { if([viewController isKindOfClass:[THIRDVIEWCONTROLLER class]]) { [self.tabBarController setSelectedViewController:viewController]; } }
    【解决方案2】:

    您可以使用我正在做的触摸委托方法弹出到上一个视图

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
    
        CGPoint startPosoition = [touch previousLocationInView:self.view];
    
    
        CGPoint endPosition = [touch locationInView:self.view];
    
        if (endPosition.x - startPosoition.x > 20)
        {
            [self.navigationController popViewControllerAnimated:YES];
        } else
        {
        }
    }
    

    【讨论】:

      【解决方案3】:

      是的,可以做到。对于 1. 我假设您知道如何使用视图控制器设置基于标签栏的应用程序。对于 2. 在您的第二个视图控制器的视图和手势处理程序中实现滑动手势识别器:[self.yourTabBarController setSelectedIndex:2];

      【讨论】:

        【解决方案4】:

        使用此代码;

        UISwipeGestureRecognizer *swipeGestureNextPage = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(loadPreviousPageClicked)];
         swipeGestureNextPage.direction = UISwipeGestureRecognizerDirectionRight;
         [self.view addGestureRecognizer:swipeGestureNextPage];
        
        -(void)loadPreviousPageClicked
        {
        
        //use navigation controller here accordingly
        
        }
        

        就是这样。

        【讨论】:

          猜你喜欢
          • 2014-11-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-06-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多