如何在没有NavigationController的情况下推送子ViewController?

发布于 2024-11-09 00:40:09 字数 422 浏览 0 评论 0原文

我想将 viewController 推送到我的主 viewController 上的一个区域。据我了解,除非将 NavigationController 添加到 UIWindow 中,否则无法使用它。

这个动画让人想起 UIScrollView 水平滚动。但我希望它像导航控制器一样工作。当用户按下特定操作时,视图控制器将发生变化。

ViewController2 将是一个带有一些其他按钮的 tableView。

ViewController3 将是一个从 tableView 更改对象的表单。

动画视图控制器

I want to push viewControllers to an area on my main viewController. From what I understand, you can't use a NavigationController unless you are adding it to a UIWindow.

This animation reminds of UIScrollView horizontal scrolling. But I want it to work like a NavigationController instead. The ViewControllers will be changed when the user presses on specific actions.

ViewController2 is going to be a tableView with some other buttons.

ViewController3 is going to be a form to change the object from the tableView.

Animation of viewControllers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雪落纷纷 2024-11-16 00:40:09

我最近在 UIView 中发现了一种方法,可以在切换视图时产生“推或弹出”的感觉。

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

这是直接来自 UIView 文档的,所以我建议查看 UIView 类参考 查看具体内容。基本上,它将一个视图切换到另一个视图,而 options: 部分允许您从多种不同的样式中进行选择。

I recently found a method in UIView that creates a "push or pop" feel to switching views.

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

This is straight out of the UIView documentation, so I would recommend looking at the UIView Class Reference to see the specifics. Basically, it switches a view to another view, while the options: section lets you pick from a multitude of different styles.

对岸观火 2024-11-16 00:40:09

我实际上通过使用 UIView 动画解决了这个问题。

-(void)slideInView:(UIView*)newView toView:(UIView*)oldView {
    /* Sets the view outside the right edge and adds it to mainView */
    newView.bounds = mainView.bounds;
    newView.frame = CGRectMake(newView.frame.origin.x + 784, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height);
    [mainView addSubview:newView];

    /* Begin transition */
    [UIView beginAnimations:@"Slide Left" context:oldView];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDelay:0.0f];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationDidStopSelector:@selector(slideInCompleted:finished:context:)];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    newView.frame = CGRectMake(0,0, newView.frame.size.width, newView.frame.size.height);
    oldView.frame = CGRectMake(oldView.frame.origin.x - 784, oldView.frame.origin.y, oldView.frame.size.width, oldView.frame.size.height);
    [UIView commitAnimations];
}

-(void)slideInCompleted:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    UIView *view = (UIView*)context;
    [view removeFromSuperview];
}

并使用它

menuController = [[MenuViewController alloc] init];
[self slideOutView:menuController.view toView:loginController.view];
[oldController release];

请记住,您已经分配了一个 UIViewController,当您使用完它时需要释放它!在示例中,我完成了 loginController 并释放了它。

I Actually solved it by playing around with UIView Animations.

-(void)slideInView:(UIView*)newView toView:(UIView*)oldView {
    /* Sets the view outside the right edge and adds it to mainView */
    newView.bounds = mainView.bounds;
    newView.frame = CGRectMake(newView.frame.origin.x + 784, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height);
    [mainView addSubview:newView];

    /* Begin transition */
    [UIView beginAnimations:@"Slide Left" context:oldView];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDelay:0.0f];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationDidStopSelector:@selector(slideInCompleted:finished:context:)];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    newView.frame = CGRectMake(0,0, newView.frame.size.width, newView.frame.size.height);
    oldView.frame = CGRectMake(oldView.frame.origin.x - 784, oldView.frame.origin.y, oldView.frame.size.width, oldView.frame.size.height);
    [UIView commitAnimations];
}

-(void)slideInCompleted:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    UIView *view = (UIView*)context;
    [view removeFromSuperview];
}

and to use it

menuController = [[MenuViewController alloc] init];
[self slideOutView:menuController.view toView:loginController.view];
[oldController release];

Remeber that you have alloced a UIViewController that you need to release when you are done useing it! In example i'm done with loginController and releasing it.

红焚 2024-11-16 00:40:09

如果没有 UINavigationController,绝对无法本地“推送”任何控制器。但是,您可以对视图进行动画进出。

根据您发布的示例,简单的 UIScrollView 看起来将是您最简单的选择。

There's absolutely no way to "push" natively any controller without a UINavigationController. You can however, animate views in and out.

With the example you have posted, it looks like a simple UIScrollView would be your easiest option.

天赋异禀 2024-11-16 00:40:09

我会使用 UIScrollView,因为它能够捕捉到内置的“页面”。您也可以使用 setContentOffset:animated: 滚动到任何部分。

I’d use a UIScrollView, as it has the ability to do snapping to "pages" built in. You can also scroll to any part with setContentOffset:animated: as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文