当UINavigationController以模态方式呈现时,UIBarButtonItems移位

我在iOS应用程式扩充功能中以模态方式呈现UINavigationController:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];       
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:nav animated:YES completion:nil];

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

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

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

我不会覆盖viewDidAppear(这似乎是按钮跳跃的点).

在我的应用程序内提交相同的导航控制器/根视图控制器,而不是应用程序扩展,不会给我同样的问题.有任何想法吗?

解决方法

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

如果您的缩位困扰您,您还可以在按钮的外侧设置负的固定空间,使其更靠近边缘.

这里有一个例子,包括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];

这只会在我的分机扩展上发生,我没有任何与分离的控制器或任何类似的内容相关的问题.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...