iphone - 如何制作一个管理两个 subview Controller 的父 View Controller

标签 iphone ios uiviewcontroller

我正在努力向应用程序添加一些功能,该功能与 iOS 上 Springboard 上的应用程序切换抽屉非常相似。我希望能够有一个按钮,我可以点击该按钮来动画 View 的 y 坐标,以便在底部暴露另一个 View 。就像我说的,与 iOS 上的主页按钮双击功能非常相似。

环顾四周后,我似乎需要将两个 subview Controller 包装到一个父 View Controller 中。

我怎样才能做到这一点?现有的 View Controller 非常复杂,所以我很难弄清楚从哪里开始。

最佳答案

我不知道您需要使用父 View Controller 来执行此操作。这段代码对我有用,可以做我认为你想要的事情。我有一个 BOOL ivar 来跟踪底部 View 是否已显示,并使用主视图中的相同按钮在两种状态之间切换。

-(IBAction)slideInController:(UIButton *) sender {
    if (viewRevealed == NO) {
        next = [self.storyboard instantiateViewControllerWithIdentifier:@"Blue"];
        next.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + self.view.frame.size.height, self.view.frame.size.width, 100); // my NextController's view was made 100 points high in IB.
        [self.view.window addSubview:next.view];
        [UIView animateWithDuration:.6 animations:^{
            self.view.center = CGPointMake(self.view.center.x, self.view.center.y - 100);
            next.view.center = CGPointMake(next.view.center.x, next.view.center.y - 100);
        } completion:^(BOOL finished) {
            viewRevealed = YES;
        }];
    }else{
        [UIView animateWithDuration:.6 animations:^{
            self.view.center = CGPointMake(self.view.center.x, self.view.center.y + 100);
            next.view.center = CGPointMake(next.view.center.x, next.view.center.y + 100);
        } completion:^(BOOL finished) {
            [next.view removeFromSuperview];
            viewRevealed = NO;
        }];
    }
}

我通常使用容器 View Controller 来做这种事情,但这很有效,而且非常简单。

关于iphone - 如何制作一个管理两个 subview Controller 的父 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14250499/

相关文章:

ios - 如何禁用 UIApplication.keyWindow() 呈现的 ViewController 上的方向

iphone - 如何判断是否存在模式 UIViewController?

ios - iPhone 模拟器与 Xcode 预览不匹配

iphone - 在 iPhone 操作系统上检测文件创建日期?

iphone - 如何将架构armv7、armv7s添加到{name}.framework?

ios - "Also create xib file"按钮禁用

iphone - 如何使用 UITapGestureRecognizer 同时检测点击和双击?

ios - 在没有状态栏的情况下使用 safeAreaLayoutGuide

导航栏中的ios标题和副标题居中

iphone - 用于推送 UIViewController 的自定义动画