0

我将在导航栏和视图控制器内容之间的差距中创建“无连接”视图。导航栏和视图控制器内容之间的差距

我想继承UINavigationViewController并将视图控制器的内容向下移动一下。

问题是如何以正确的方式做到这一点?

我目前的解决方案工作,但它也很hacky。我想让它变得更好。

// subclass of AGNavigationController 
-(void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    static BOOL firstTime = YES; 
    if (firstTime) { 
     contentView = nil; 
     for (UIView *v in self.view.subviews) { 
      if ([v isKindOfClass:[NSClassFromString(@"UINavigationTransitionView") class]]) { 
       contentView = v; 
       break; 
      } 
     } 
     firstTime = NO; 
     origFrame = contentView.frame; 
     noConnectionView.frame = CGRectMake(0, self.navigationBar.frame.origin.y+self.navigationBar.frame.size.height, 320, 20); 
    } 
    [self adjustToConnection:NO withAnimation:NO]; 
} 

-(void)adjustToConnection:(BOOL)isConnection withAnimation:(BOOL)animation { 
    if (isConnection) { 
     [noConnectionView removeFromSuperview]; 
     contentView.frame = origFrame; 
    } else { 
     [self.view addSubview:noConnectionView]; 
     contentView.frame = CGRectMake(0, origFrame.origin.y+20, 320, origFrame.size.height-20); 
    } 
} 

回答

0

创建UIView并设置它的框架像(0, 0, self.view.frame.size.witdh, 40)

使用[self.view addSubview:myView];将视图添加到您的UIViewController

将您的元素向下移动到主视图中,垂直偏移设置为myView.frame.size.height

这就是你可以得到像这样的问题。如果你需要更多的帮助,你必须对你的尝试做更精确的描述,并且哪些行不通。

相关问题