2015-11-25 124 views
0

我有一個容器UIViewController(IntroViewController),其中我加載UIPageViewController(PageViewController)。在UIPageViewController中,我有IntroPageContentViewControllersLastIntroPageContentViewControlleriOS UIPageViewController與背景

My storyboard setup

我想有在UIPageViewController的背景圖像。如果我把它放在IntroViewController中,它是不可見的。我不能把它放在UIPageViewController中,當我把它放入其中一個​​時,它會滾動出入每一頁。我希望它在一個地方,只能滾動內容。

我在哪裏把UIImageView和我應該在哪裏bringSubviewToFront或類似的東西?

回答

2

簡而言之的UIImageView到容器UIViewController並設置view.backgroundColor屬性[UIColor clearColor]用於內容視圖控制器。

在這裏你有它是如何工作的例子: https://github.com/Wojdan/stackAnswers/tree/master/33912671

+0

感謝您的回答!我喜歡你在Github上的例子,非常聰明。 我會克隆並看看它是如何工作的。我確實需要容器控制器上的白色背景,然後在其上放置一個圖像,所以我會嘗試。 – jbehrens94

1
UIView *view = [[UIView alloc] init]; 
view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_backgroung"]]; 
imageView1.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 
[view addSubview:imageView1]; 

// Create page view controller 
self.pageViewController = [self.storyboard 
instantiateViewControllerWithIdentifier:@"PageViewController"]; 
self.pageViewController.dataSource = self; 
self.pageViewController.view.backgroundColor = [UIColor clearColor];     
[self.pageViewController.view insertSubview:view atIndex:0]; 



UIPageControl *pageControl = [UIPageControl appearance]; 
pageControl.pageIndicatorTintColor = [UIColor whisperWhite]; 
pageControl.currentPageIndicatorTintColor = [UIColor whisperDarkGray]; 
pageControl.backgroundColor = [UIColor clearColor]; 
+0

//我還有一個解決方案: – user5598510

+0

這不起作用。它給我一個黑色的背景,圖像不顯示。 – jbehrens94

0

理想情況下,你應該加入UIPageViewController爲parentViewController它的孩子。在你的情況下,IntroViewController是父項,PageViewController將成爲它的子項。

現在,你從圖像設置IntroViewController背景色象下面這樣:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]; 

然後,您可以清除背景顏色爲內容視圖控制器這是你打算加入到UIPageViewController

但是,您可能有以下代表發表意見,以從`UIPageViewController」

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController 
{ 
} 

希望底部刪除頁面控制這會有所幫助。