【问题标题】:swipe to change uiviewcontroller滑动更改 uiviewcontroller
【发布时间】:2014-07-08 09:47:07
【问题描述】:

我有一个viewController,其中包含将在viewController 的上半部分保持静态的数据。下半部分包含 4 个按钮和 4 个 UIViewControllers 链接到之前加载的 4 个按钮。并在相应的按钮上单击相应的UIViewController 将显示,其余的将被隐藏。我只是在单击按钮时使viewController 可见和不可见。

我想让它们在滑动时改变。所以UIViewController 会随着滑动而改变,相应UIViewController 的按钮状态也会随着滑动而改变。

我没有使用故事板,而是使用 xcode5。

【问题讨论】:

  • 如果您在滑动时更改视图控制器,那么您为什么需要按钮?
  • @KananVora 它必须同时处理视图控制器应该在按钮单击和滑动时更改
  • 为什么要投反对票,请提供投反对票的理由?
  • 因为你还没有证明你已经对这个问题进行了深入的研究。你做了什么/尝试了什么?什么不起作用?你的代码是什么样的?

标签: objective-c uiviewcontroller xcode5 uiswipegesturerecognizer


【解决方案1】:

一种简单的方法 - 您可以使用UITabBarController 来处理所有这些视图控制器数组:https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html 并通过滑动更改它们 - 只需添加 UISwipeGestureRecognizer: https://developer.apple.com/library/ios/documentation/uikit/reference/UISwipeGestureRecognizer_Class/Reference/Reference.html 就像这样:

UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changeTabs:)]; [self.view addGestureRecognizer:swipeRecognizer]; [swipeRecognizer release]; 在changeTabs: 中这样做

[self.tabBarController setSelectedViewController:nextViewController];

另一种更可靠的方法是使用 UIPageViewController : https://developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html

您写道:"so the uiviewcontroller will change with the swipe and the button state for the respective uiviewcontroller will also change with swipe." - 这很愚蠢。只需按照我的建议使用任一选项卡并删除这些按钮或使用 UIPageViewController 已经有页面指示器并会自行处理它们的逻辑

【讨论】:

  • 我几乎已经完成了申请,快到截止日期了,客户希望通过点击按钮和滑动两种方式来处理它,我是 IOS 新手,所以不知道该怎么做。请帮帮我。
猜你喜欢
  • 1970-01-01
  • 2013-02-17
  • 2011-05-24
  • 2011-05-28
  • 1970-01-01
  • 2016-01-24
  • 1970-01-01
  • 2015-12-03
  • 2011-06-23
相关资源
最近更新 更多