当UINavigationController以模态方式呈现时,UIBarButtonItems移位 [英] UIBarButtonItems shift position when UINavigationController is presented modally

查看:150
本文介绍了当UINavigationController以模态方式呈现时,UIBarButtonItems移位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS应用扩展程序中以模态方式呈现 UINavigationController

I'm presenting a UINavigationController modally, from within an iOS app extension:

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];       
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:nav animated:YES completion:nil];

当导航控制器出现时,其根视图控制器的 UIBarButtonItems 跳跃位置:

When the navigation controller appears, its root view controller's UIBarButtonItems jump position:

我正在 viewDidLoad 中创建并添加按钮。它们只是标准的条形按钮项:

I'm creating and adding the buttons in viewDidLoad. They are just standard bar button items:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];

我没有覆盖 viewDidAppear (其中似乎是按钮跳转的点。。

I'm not overriding viewDidAppear (which appears to be the point where the buttons jump).

从我的应用程序中呈现这个相同的导航控制器/根视图控制器,而不是应用程序扩展,不会给出我同样的问题。有什么想法吗?

Presenting this same navigation controller/root view controller from within my app, instead of the app extension, doesn't give me this same problem. Any ideas?

推荐答案

我希望别人找到更好的方法来做到这一点,但我目前的解决方案是创建立场单独按钮然后使用按钮使用 [[UIBarButtonItem alloc] initWithCustomView:] 。不理想,并且凹痕仍然存在,但奇怪的跳跃不再发生。

I'm hoping someone else finds a better way to do this, but my current solution is to create stand alone buttons and then use [[UIBarButtonItem alloc] initWithCustomView:] with the button. Not ideal, and the indention is still there, but the weird jump doesn't happen anymore.

如果凹痕困扰你,你也可以设置负的固定空间按钮的外侧将它们移近边缘。

If the indention bothers you, you could also set negative fixed spaces on the outsides of the buttons to shift them closer to the edges.

以下是包含垫片的示例:

Here's an example including the spacer:

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
<other button config here, set targets, whatever>
[button sizeToFit];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:button];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixedSpace setWidth:-8.0f];

self.navigationItem.leftBarButtonItems = @[fixedSpace, leftBarButton];

这只发生在我的分享扩展中,我没有任何与呈现有关的问题来自一个独立的控制器或类似的东西。

This only happens to me on my share extension, and I don't have any problems related to presenting from a detached controller or anything like that.

这篇关于当UINavigationController以模态方式呈现时,UIBarButtonItems移位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆