ios - 如何在两个 UIView 之间实现 "90% slide"

标签 ios cocoa-touch uiview uiviewcontroller uiviewanimation

我有一个我正在尝试模拟的特定场景,并且由于对 Cocoa Touch 还很陌生,所以我不确定完成它的最佳方法。请原谅我缺乏战术知识;希望一些明确的说明会有所帮助。

我想模拟的内容:

我正在查看(特别是)的应用程序是 Beat .下面是他们的 UIView 之一的示例 - 特别要注意底部的设置齿轮图标。

enter image description here

当触摸或向上滑动该齿轮时,会发生两个主要的 UIView 更改:

  1. 原始 UIView 在屏幕上向上滑动了大约 90%(关键点是它不会全部向上滑动)。
  2. 向上滑动一个新的 UIView 以填充新腾出的 90% 空间。

enter image description here

这是我想要完成的基本功能。

实现思路 #1:带有多个 UIView 的单个 UIViewController

起初,我考虑过让一个 UIViewController 管理“主” View 和“设置” View 。在那种情况下,以适当的方式转换这些 View 将是一件相当简单的事情。

也就是说,这对我来说似乎有点困惑。根据我的两组功能的稳健程度,这是重载单个 UIViewController 的方法。您可能会告诉我这没关系,但实际上,这似乎太多了。

实现思路 #2:自定义容器 ViewController 中的多个 UIViewController

这是我目前要走的路线。它将两组离散的功能分离为单独的 UIViewController(包含在 Container ViewController 中)并通过以下方式在两者之间进行转换:

- (void)flipFromViewController:(UIViewController *)fromController
              toViewController:(UIViewController *)toController
{
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;

    fromController.view.frame = CGRectMake(0.0f, 0.0f, width, height);
    toController.view.frame = CGRectMake(0.0f, height, width, height);

    [self addChildViewController:toController];
    [fromController willMoveToParentViewController:nil];

    [self transitionFromViewController:fromController
                      toViewController:toController
                              duration:0.5f
                               options:UIViewAnimationOptionTransitionNone
                            animations:^(void) {
                                fromController.view.frame = CGRectMake(0.0f, -(height - 100.0f), width, height);
                                toController.view.frame = CGRectMake(0.0f, 100.0f, width, height);
                            }
                            completion:^(BOOL finished) {
                                [fromController removeFromParentViewController];
                                [toController didMoveToParentViewController:self];
                            }];
}

这个问题是过渡:它似乎并没有停止“90% 的方式”。它看起来更像是打算完全过渡出“旧” Controller 和"new" Controller ,即使我对两个 UIView 的框架调整不应该是“完整”的移动。

我需要指导的地方

我不要求完整的解决方案 - 您的专业知识太昂贵了。 :) 话虽如此,我对此还很陌生,希望您能洞察正确的方法。如果我可以提供更多信息,请告诉我。

谢谢!

最佳答案

我确实认为您的第二种方法是正确的,并且您对使用 transitionFromViewController:ToViewController 的直觉也是正确的——如果您希望两个 View Controller 都存在并处于事件状态,我不会使用该方法。因此,我会让带有齿轮 View 的 Controller 成为自定义容器 Controller 的 subview Controller ,然后像您一样将屏幕外的第二个 subview 添加到底部。然后使用 animateWithDuration 为两个 View 设置动画:...最后,动画,你应该得到你想要的,你的容器 Controller 将有两个 child 。

关于ios - 如何在两个 UIView 之间实现 "90% slide",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18107373/

相关文章:

ios - SpriteKit iPhone/iPhoneX/iPad 尺寸问题

android - 手机间隙 : Add android platform to an already built app

ios - 当手指触摸/拖动时更改 UIButton 大小

iphone - 使用 Core Data/NSFetchedResultsController 进行键入搜索

ios - 从中间屏幕开始对齐 UIVIew

iphone - iPhone 中的同级 subview 不接收触摸

iOS - 如果 UITextView 正在 if 语句中编辑

javascript - JS 中的 getCurrentPosition 在 iOS 上不起作用

iphone - 调试器错误

ios - 触摸开始 : inside UITableView