如何将 UIToolbar 与其父视图一起转换

发布于 2024-11-07 02:30:29 字数 204 浏览 5 评论 0原文

如何从一个 UIViewController (带底部工具栏)过渡到另一个 UIViewController (不带工具栏),以便在动画进行时,工具栏随第一个视图移开,这意味着工具栏保持在第一个视图的初始位置看法?

我在“Things”应用程序中看到过这种行为。

需要明确的是,我并不是在寻找诸如隐藏/显示 viewDidAppear 内的工具栏之类的解决方案。

How can I transition from one UIViewController (with bottom toolbar) to another one (without toolbar), so that while the animation is in progress, the toolbar moves away with the first view, meaning that the toolbar stays in it's initial position of the first view?

I've seen this behaviour in "Things" app.

Just to be clear, I am not looking for solutions such as hiding/showing the toolbar inside viewDidAppear.

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

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

发布评论

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

评论(2

百变从容 2024-11-14 02:30:30

所以,这是一个我不太满意的解决方案,但目前它似乎是唯一的解决方案。

重点是忽略 UINavigationController 的内置工具栏属性,创建单独的 UIToolbar 并将其放置在视图控制器中。

// Create your bar items
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

NSArray *toolbarItems = [[NSArray alloc] initWithObjects: flexibleSpace, nil];
[flexibleSpace release], flexibleSpace = nil;

UIToolbar *customToolbar = [[UIToolbar alloc] init];
[customToolbar sizeToFit];
[customToolbar setFrame:CGRectMake(0.0, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height - customToolbar.frame.size.height, customToolbar.frame.size.width, customToolbar.frame.size.height)];
[customToolbar setItems:toolbarItems];
[[self view] addSubview:customToolbar];
[customToolbar release], customToolbar = nil;

[toolbarItems release], toolbarItems = nil;

这样,工具栏将随其视图滑走,不会导致动画问题,例如“白色矩形”或放置在 viewDidAppear 中时迟到出现的工具栏...

So, this is a solution I wasn't very happy about, but at the moment it seems as the only one.

The point is to ignore the built in toolbar property of UINavigationController, create separate UIToolbar and place it inside your view controller.

// Create your bar items
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

NSArray *toolbarItems = [[NSArray alloc] initWithObjects: flexibleSpace, nil];
[flexibleSpace release], flexibleSpace = nil;

UIToolbar *customToolbar = [[UIToolbar alloc] init];
[customToolbar sizeToFit];
[customToolbar setFrame:CGRectMake(0.0, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height - customToolbar.frame.size.height, customToolbar.frame.size.width, customToolbar.frame.size.height)];
[customToolbar setItems:toolbarItems];
[[self view] addSubview:customToolbar];
[customToolbar release], customToolbar = nil;

[toolbarItems release], toolbarItems = nil;

This way the toolbar will slide away with it's view, causing no animation issue such as "white rectangles" or late appearing toolbar when placed in viewDidAppear...

撑一把青伞 2024-11-14 02:30:30

听起来你想要:

- ( void )viewWillAppear: (BOOL)animated
{
    NSArray            *items = ... UIBarButtonItem array...;

    [ super viewWillAppear: animated ];

    [ self setToolbarItems: items animated: animated ];

    ....
}

It sounds like you want:

- ( void )viewWillAppear: (BOOL)animated
{
    NSArray            *items = ... UIBarButtonItem array...;

    [ super viewWillAppear: animated ];

    [ self setToolbarItems: items animated: animated ];

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