gpt4 book ai didi

ios - 在独立 View 中使用时,iOS 8 中屏幕边缘的 UIBarButton 项目

转载 作者:技术小花猫 更新时间:2023-10-29 10:53:08 26 4
gpt4 key购买 nike

在我的 UINavigation 栏中,添加到带有多个 UIView 的 XIB 中,左右栏按钮项目的位置偏离了:

Navigation bar in additiona UIView in XIB

XIB 中的 View 只是有一个 View Controller 的导出,但不是主视图。显示方式:

[UIView transitionFromView:self.view toView:self.settingsView duration:0.2 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];

我有另一个更简单的 View ,它直接绑定(bind)到 View Controller 的 View 属性,正如预期的那样,它看起来很正常。

Normal navigation bar

所有 View 都有自动布局。约束很好。我尝试了很多不同的方法,但无法提出解决方法(或原因)。导航栏和项目只是普通的 Vanilla 栏按钮项目,没有任何外观代理等...

在 7.1 sim 中,一切看起来都很正常。

有人以前见过这个吗?

谢谢

[编辑]

我找到了解决方法但找不到原因:

如果我代替

[UIView transitionFromView:self.view toView:self.settingsView duration:0.2 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];

将新 View 添加为 UIWindow 的 subview ,

使用这个:

[UIView transitionWithView:self.view duration:0.2 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self.view addSubview:self.settingsView];
} completion:nil];

将新 View 添加为现有 UIViewControllers View 的 subview ,一切正常。

我想知道如果包含在动态添加到窗口的 View 中,这是否是一个错误和 UINavigationBars 以奇怪的方式呈现...

最佳答案

不确定 UIBarButtonItem 发生了什么。它应该通过自动布局进行排列,并且必须运行良好。可能是约束之一与其他约束冲突或被误导。

如果你无法解决它。我为您提供了另一种解决方案。您需要在 VC 中以编程方式创建 UIBarButtonItem

想法是在添加 UIBarButtonItem 之前从左右填充分配空间。

下面的代码将指导您完成这个技巧。

UIBarButtonItem *leftPadding = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemFixedSpace target:self action:nil];
[leftPadding setWidth:5]; // Adjust width for padding from left side.

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemAdd target:self action:@selector(addButtonTapped:)];
[self.navigationItem setLeftBarButtonItems:@[leftPadding, addButton]];


UIBarButtonItem *rightPadding = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemFixedSpace target:self action:nil];
[rightPadding setWidth:10]; // Adjust width for padding from right side.

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone target:self action:@selector(doneButtonTapped:)];

[self.navigationItem setRightBarButtonItems:@[rightPadding, doneButton]];

关于ios - 在独立 View 中使用时,iOS 8 中屏幕边缘的 UIBarButton 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26475796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com