2013-05-14 38 views
1

如果我將某些內容推送到導航控制器然後彈回到主頁,我的主頁中的scrollview停止工作。如果我重新打開應用程序而不向導航控制器推送任何東西,它正常工作。滾動視圖是延伸到框架外的水平滾動視圖。我使用它來滾動瀏覽按鈕,例如在iOS中切換應用程序(iOS多任務)。UIScrollView在將視圖推送到UINavigationController後停止工作

這是我推一個新的VC

UIViewController *newVC = [[UIViewController alloc] init];  
    UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds]; 
    [label setTextAlignment:NSTextAlignmentCenter]; 
    label.text = [NSString stringWithFormat:@"promo %i detail view",[sender tag]]; 
    label.backgroundColor = [UIColor whiteColor]; 
    [newVC.view addSubview:label]; 

    [self.navigationController setNavigationBarHidden:NO animated:NO]; 
    [self.navigationController pushViewController:newVC animated:YES]; 

當視圖控制器彈出,導航控制器回遷主頁我隱藏的導航欄的代碼。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
     if(viewController == self){ 
      [self.navigationController setNavigationBarHidden:YES]; 
      NSLog(@"%d", [self.scrollMenuBar isScrollEnabled]); 
     } 
    } 

檢查isScrollEnable返回true。

我試着推動一個普通的模態視圖,併發生同樣的問題。

+0

還檢查scrollView的內容大小,它保持不變。坡平 – Bonnie 2013-05-14 09:10:06

+0

是之後,它仍然是相同的@Bonnie – harinsa 2013-05-14 09:14:01

回答

0

問題通過創建的UIScrollView和編程裏面的按鈕解決。不知道我的故事板有什麼問題,但這是一種痛苦。

+0

也許禁用Autolayout也可以解決問題。 – harinsa 2013-05-20 05:00:31

0

在viewdidAppear添加 [self.scrollbarMenu setScrollEnabled:YES];主網頁

添加

[scroll setContentSize:CGSizeMake(width , height)]; 

不過,如果它不工作 2的可能性

  1. 內存無效。
  2. 其它一些視圖來滾動視圖上述
+0

仍然無法正常工作 – harinsa 2013-05-14 09:19:48

+0

添加內容的大小也有,然後再試一次 – 2013-05-14 09:24:12

+1

仍然無法正常工作,我檢查了scrollEnable和contentSize仍然流行 – harinsa 2013-05-14 09:27:47

1

如果您調整viewDidLayoutSubview函數中的滾動視圖內容大小,它將再次工作。

- (void) viewDidLayoutSubviews { 
    [self resizeScrollViewContent]; 
} 
相關問題