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

這就是你可以得到像這樣的問題。如果你需要更多的幫助,你必須對你的嘗試做更精確的描述,並且哪些行不通。

相關問題