我不認爲你會需要兩個單獨的視圖控制器。您只需在UIViewController
中自定義UIScrollView
即可。
首先,你需要設置你的scrollView的內容大小。然後,您需要防止UIScrollView
滾動,因爲您不希望它滾動。
self.scrollView =[[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.scrollView.delegate = self;
self.scrollView.contentSize = CGSizeMake(320, 568 + x ); // x represents the height of white screen in your first view controller.
self.scrollView.bounces = NO;
self.scrollView.scrollEnabled = NO;
其次,你添加一個UITapGestureRecognizer
您UIView
,將需要在屏幕上顯示完全。下面是一段代碼,你可以通過改變你的UIScrollView
的contentOffset
使用
UITapGestureRecognizer *tapGestureRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapped:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[view addGestureRecognizer:tapGestureRecognizer];
最後,你可以實現tapped
方法在屏幕上顯示全新UIView
。不要忘記消失導航欄。所以,
- (void)tapped{
self.navigationController.navigationBarHidden = YES;
[self.scrollView setContentOffset:CGPointMake(0,view1.frame.origin.y) animated:YES];
}
那麼,最後,你完全顯示你的第二個視圖在屏幕上。假設您使用的iPhone> 5,但我可以使用靜態值,但您可以根據您運行的設備使用高度的動態值。別忘了在第二個視圖中輸入setUserInteractionEnabled
。
我的錯誤我認爲你不想導航欄,但沒有什麼大不了的,只是你需要改變setContentOffset的y值而不使用navigationBarHidden
屬性。
不能成爲模態視圖,因爲您將失去前一視圖的交互作用,再加上iPad上的彈出窗口以外的任何視圖,視圖控制器將全屏顯示。考慮在同一個視圖控制器上創建一個子UIView。使用手勢識別器來控制動作。 –