精简版:
当与自定义转换和UINavigationControlleriOS7 结合使用时,我遇到了自动布局顶部布局指南的问题.具体而言,顶级布局指南和文本视图之间的约束不受尊重.有没有人遇到过这个问题?
长版:
我有一个场景明确定义了约束(即顶部,底部,左侧和右侧),呈现如下视图:

但是当我在导航控制器上使用自定义转换时,顶部布局指南的顶部约束似乎关闭,它呈现如下,好像顶部布局指南位于屏幕顶部,而不是底部导航控制器:

使用自定义转换时,导航控制器的"顶部布局指南"似乎变得混乱.其余约束正确应用.如果我旋转设备并再次旋转它,一切都会突然正确呈现,所以看起来并不是没有正确定义约束.同样,当我关闭自定义转换时,视图会正确呈现.
话虽如此,当我运行时_autolayoutTrace报告UILayoutGuide对象受到影响AMBIGUOUS LAYOUT:
(lldb) po [[UIWindow keyWindow] _autolayoutTrace]
Run Code Online (Sandbox Code Playgroud)
但是每当我看到它们时,这些布局指南总是被报告为含糊不清,即使我已经确保没有遗漏约束(我已经习惯性地选择视图控制器并选择"为视图控制器添加缺少的约束"或选择全部控制和为他们做同样的事情).
在如何我正是这样做的过渡方面,我指定符合对象UIViewControllerAnimatedTransitioning的animationControllerForOperation方法:
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
{
if (operation == UINavigationControllerOperationPush)
return [[PushAnimator alloc] init];
return nil;
}
Run Code Online (Sandbox Code Playgroud)
和
@implementation PushAnimator
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 0.5;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
CGFloat width = fromViewController.view.frame.size.width;
toViewController.view.transform = CGAffineTransformMakeTranslation(width, 0); …Run Code Online (Sandbox Code Playgroud) 在这里看了一会儿,但似乎无法找到一个有效的解决方案.
我试图在Swift中禁用滑动以返回上一个视图手势.
我尝试了各种解决方案,包括:
self.navigationController?.interactivePopGestureRecognizer.enabled = false
Run Code Online (Sandbox Code Playgroud)
和
self.navigationController.interactivePopGestureRecognizer.delegate = self
func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer!) -> Bool {
return false
}
Run Code Online (Sandbox Code Playgroud)
是否有一种新方法可以做到这一点或其他方法有效?
更新2
我一直在使用4英寸设备在iOS模拟器中运行和测试我的应用程序.如果我使用3.5英寸设备运行,标签不会跳转.在我的.xib中,在Simulated Metrics下,我将它设置为Retina 4英寸全屏.知道为什么我只在4英寸设备上看到这个问题吗?
更新1
在IB中,如果我在模拟指标中选择"导航栏",我的标签仍然会跳转.我可以在第一个屏幕上正确呈现标签的唯一方法是不将导航控制器设置为我的窗口的根视图控制器.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我的窗口的rootViewController被设置为一个UINavigationController,其rootViewController嵌入了一个UIPageViewController.
当我的应用加载时,会显示初始视图,其内容会向下推一点,大小与导航栏大致相同.当我滚动pageViewController时,内容会跳转到它在nib中的位置,而pageViewController加载的所有其他viewControllers都可以.

在我的appDelegate中:
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ContainerViewController new]];
Run Code Online (Sandbox Code Playgroud)
在ContainerViewController中:
- (void)viewDidLoad {
[super viewDidLoad];
self.pvc = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.pvc.dataSource = self;
self.pvc.delegate = self;
DetailViewController *detail = [DetailViewController new];
[self.pvc setViewControllers:@[detail]
direction:UIPageViewControllerNavigationDirectionForward
animated:false
completion:nil];
[self addChildViewController:self.pvc];
[self.view addSubview:self.pvc.view];
[self.pvc didMoveToParentViewController:self];
}
Run Code Online (Sandbox Code Playgroud) xcode objective-c uinavigationcontroller ios uipageviewcontroller
使用navigationItem.titleView在iOS11上查看行为,其中titleView的宽度不是屏幕的整个宽度.
我有一个自定义视图,我将其设置为titleView.在iOS11之前,视图将填充导航栏区域.但iOS 11并没有调整大小来填充屏幕的宽度.
我在设置titleView之前尝试设置视图的框架,但没有运气.我试图强制titleViews superview布局约束,但没有运气.
附上截图:
iOS10:
iOS11:
还有其他人经历过吗?
uinavigationbar uinavigationcontroller navigationitem ios ios11
我想UINavigationBar在我的一个视图中使用自定义,这不是任何UINavigationController-hierarchy 的一部分.当我将其UINavigationBar拖入Storyboard时,它显示如下:

这个条是44像素,如果状态栏不共享这个空间就足够了.因为iOS7让我们使用整个屏幕,包括状态栏的空间,UINavigationBar应该是64px高,而不是44px.
如果我将视图连接到一个UINavigationController层次结构,那么它显示正确:

我读的地方,如果在UINavigationBar有属性barPosition:设置为UIBarPositionTopAttached,那么酒吧是64PX.然而,这是一个readonly属性.
我的搜索结果只显示了我认为是"解决方法"的问题.通过UINavigationController在此之前添加无用UIViewController,我可以假装有一个层次结构,它将自动添加UINavigationBar64px.
是否真的没有办法UINavigationBar覆盖64px 的"流氓"(没有导航控制器的帮助)?如果是这样的话,是否有任何正当理由说明原因?
(我不是说UINavigationBar默认情况下应该是64px,但是在检查器中应该有一个选项)
(我也看到人们用程序化的方式来解决这个问题.尽管这些答案有效,但我仍然需要设计故事板,考虑到这一点(差距).我想知道的是,是否可以将其设置为故事板,或者说,为什么不允许?)
cocoa-touch objective-c uinavigationbar uinavigationcontroller ios
我从这里得到了相反的问题.默认情况下iOS7,UINavigationController堆栈的后滑动手势可以弹出呈现的内容ViewController.现在我只是穿着所有self.navigationItem.leftBarButtonItem风格的制服ViewControllers.
这是代码:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:LOADIMAGE(@"back_button") style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
Run Code Online (Sandbox Code Playgroud)
之后,navigationController.interactivePopGestureRecognizer被禁用.如何在不删除自定义的情况下启用弹出手势leftBarButtonItem?
谢谢!
objective-c uinavigationbar uinavigationcontroller uinavigationitem ios
我有导航栏和标签栏的视图.我想要发生的是隐藏某个视图上的标签栏,并在用户更改视图时再次显示标签栏.
我看到一段用于隐藏标签栏的代码:
-(void)makeTabBarHidden:(BOOL)hide
{
// Custom code to hide TabBar
if ( [tabBarController.view.subviews count] < 2 ) {
return;
}
UIView *contentView;
if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
contentView = [tabBarController.view.subviews objectAtIndex:1];
} else {
contentView = [tabBarController.view.subviews objectAtIndex:0];
}
if (hide) {
contentView.frame = tabBarController.view.bounds;
}
else {
contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
tabBarController.view.bounds.origin.y,
tabBarController.view.bounds.size.width,
tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
}
tabBarController.tabBar.hidden = hide;
}
Run Code Online (Sandbox Code Playgroud)
来自:http://nickwaynik.com/iphone/hide-tabbar-in-an-ios-app/
我在视图中调用它,我希望隐藏标签栏
[self makeTabBarHidden:YES];
Run Code Online (Sandbox Code Playgroud)
当我在该视图上显示/隐藏它时,它工作正常但当我导航回到上一个视图时,那里的标签栏也是隐藏的.我试着打电话给在视图中的该功能viewDidUnload,viewWillDisappear,viewDidDisappear功能,但没有任何反应.当函数被调用在前面视图的情况也是如此viewDidLoad, …
我有系统"NavigationViewController - > MyViewController",我编程想要在第三个视图控制器中呈现MyViewController.问题是我在呈现它之后在MyViewController中没有导航栏.你能帮助我吗?
var VC1 = self.storyboard.instantiateViewControllerWithIdentifier("MyViewController") as ViewController
self.presentViewController(VC1, animated:true, completion: nil)
Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller viewcontroller ios swift
我在UIViewController中为我的一个标签执行此操作:
self.title = @"Welcome";
Run Code Online (Sandbox Code Playgroud)
但是,它覆盖了我对tabBarItem的所有功能.我试过了:
self.tabBarItem.title = @"Home";
Run Code Online (Sandbox Code Playgroud)
和
[self.tabBarItem initWithTitle:@"Home" image:[UIImage imageNamed:@"iconHome.png"] tag:0];
Run Code Online (Sandbox Code Playgroud)
但仍然,self.title会覆盖tabBarItem,无论我是否在设置标题后尝试后两段代码.代码甚至运行没有错误,但是self.tabBarItem.title或者initWithTitle没有做任何事情?
我有一个UIViewController,我正在从我的第一个视图控制器导航到第二个视图控制器,我想要更改显示的按钮的名称navigationcontroller以便返回....
SecondViewController *secondController = [[SecondViewController alloc]
initWithNibName:nil
bundle:NULL];
[self.navigationController pushViewController:secondController animated:YES];
Run Code Online (Sandbox Code Playgroud)
现在在第二个viewcontroller我想改变按钮的名称navigationController.
uiviewcontroller uinavigationcontroller uinavigationitem ios
ios ×8
objective-c ×3
swift ×2
autolayout ×1
cocoa-touch ×1
ios11 ×1
ios7 ×1
iphone ×1
xcode ×1