【问题标题】:Tabbar Controller with swipe effect具有滑动效果的标签栏控制器
【发布时间】:2013-06-21 18:42:44
【问题描述】:

我正在尝试做一个如下效果的 Tabbar 控制器:

通过滑动视图控制器将重定向到下一个选项卡。我们如何在 iOS 中实现这一点?有没有其他控件可以这样做?

【问题讨论】:

  • 您可以将 UIScrollview 与包含视图控制器 i 一起使用。 e. addchildViewcontroller 方法...
  • @Kalpesh 有没有与此相关的示例代码?

标签: iphone ios uiviewcontroller uitabbarcontroller


【解决方案1】:

如果有人还在寻找,你可以在这个 youtube 系列上找到另一个实现

https://www.youtube.com/watch?v=3Xv1mJvwXok&list=PL0dzCUj1L5JGKdVUtA5xds1zcyzsz7HLj

编辑:

  1. 因此,据我所知,根据视频,您需要在一个视图控制器中使用两个 UICollectionViews。一个集合视图用于显示内容(应用程序),另一个用于包含类别的水平导航。

  2. 要创建绿色的“突出显示”栏,您可以使用 UIView 并使用 constraints - heightAnchor/widthAnchor 调整栏的高度/宽度并将其添加到导航栏。

  3. 要让条形图随着用户滑动的距离移动,您可以覆盖一种方法来捕获水平滚动,称为scrollViewDidScroll。从这里您需要提供来自UIView 约束(类型为NSLayoutConstraint)的变量,以便能够更新UIView 的x 位置

    override func scrollViewDidScroll(_ scrollView: UIScrollView) 
    {
        print(scrollView.contentOffset.x)
        menuBar.myGreenBarLeftConstraint.constant = scrollView.contentOffset.x / 4 
        //or however many categories you have
    }
    

【讨论】:

    【解决方案2】:

    在 GitHub 上有一个用于此的库,称为 MGSwipeTabBarController,旨在完全满足您的需求。

    就这么简单:

    NSArray *viewControllers = . . . //your view controllers
    MGSwipeTabBarController *swipeController = [[MGSwipeTabBarController alloc] initWithViewControllers:viewControllers]; 
    

    请注意,它仅与 iOS7 和 + 兼容,您仍然需要设计自己的标签栏,以使用 MGSwipeTabBarControllerDelegateprotocol 响应滚动事件。

    https://github.com/mglagola/MGSwipeTabBarController

    【讨论】:

      【解决方案3】:

      只需将 UISwipeGestureRecognizer 添加到您的 tabBarView 控制器并在滑动后更改您的 tabBar 索引。

      swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                            action:@selector(swipeMethod:)];
      swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft; 
      [self addGestureRecognizer:swipeRecognizer];  
      

      我处理滑动的方法是:

      -(void)swipeMethod: (UISwipeGestureRecognizer *) sender
      {
          NSLog(@"Swipe!");   
      } 
      

      编辑
      或者您可以使用UIScrollView 启用分页和UIView 来显示您的数据。

      这里是你要找的教程Tabbar Controller with swipte effect

      【讨论】:

      • 我知道这行得通。但是,这不会产生我期望的效果。
      • 你期待什么效果?
      • 喜欢安卓手机游戏商店
      • 您可以使用UIScrollView 启用分页和UIView 来显示您的数据。
      • 我在这找到了this,我们可以做我期望的事情。在我的应用程序中,我必须显示 3 个带有三个选项卡的 tableview。我如何通过这种滑动来做到这一点?
      【解决方案4】:

      https://github.com/nicklockwood/SwipeView 你可以使用这个类来实现你的目标......

      否则您必须使用以下方法制作用于点击标签栏的动画,

      [UIView transitionFromView:<#(UIView *)#> toView:<#(UIView *)#> duration:<#(NSTimeInterval)#> options:<#(UIViewAnimationOptions)#> completion:<#^(BOOL finished)completion#>]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-13
        • 1970-01-01
        • 2016-11-08
        • 2014-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-12
        相关资源
        最近更新 更多