2015-11-10 30 views
1

我想讓視圖出現在另一個視圖的頂部。iOS將子視圖帶回

這是我的看法層次:

enter image description here

基本上我想在屬於PageViewController的UIImageView的前面,使該按鈕(重新開始)。所以我希望能夠使用圖像頂部的按鈕進行滾動。

這裏是我的代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Create the data model 
    _pageTitles = @[@"Over 200 Tips and Tricks", @"Discover Hidden Features", @"Bookmark Favorite Tip", @"Free Regular Update"]; 
    _pageImages = @[@"page1.png", @"page2.png", @"page3.png", @"page4.png"]; 

    // Create page view controller 
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"]; 
    self.pageViewController.dataSource = self; 

    PageContentViewController *startingViewController = [self viewControllerAtIndex:0]; 
    NSArray *viewControllers = @[startingViewController]; 
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 

    // Change the size of page view controller 
    self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30); 

    [self addChildViewController:_pageViewController]; 
    [self.view addSubview:_pageViewController.view]; 
    [self.pageViewController didMoveToParentViewController:self]; 

} 
+0

不要只是把所有的代碼放在像意大利麪條那樣的牆上,並期望我們爲您分析它。什麼是_actual問題_?將視野引向前方非常簡單;爲什麼和在哪裏很難_you_? – matt

+0

我減少了發佈代碼的大小。 – radioaktiv

+1

如果你想要按鈕(我認爲它是父視圖的子視圖)出現在「PageViewController」上方,那麼你需要將「PageViewController」的視圖發送到後面或將子視圖放在前面。你試過這個嗎?它沒有工作嗎? –

回答

1

您是否嘗試過使用下面的代碼?

[self.view bringSubviewToFront:yourButtonView]; 
0

由於@iamataptool建議我帶來的PageViewController與備份:

[self.view sendSubviewToBack: _pageViewController.view]; 
0

好像你用故事板和並行編程UIView的定位。因此,你有不同的解決方案:

通過手動向上推<修復症狀 - 不推薦通過

[self.view bringSubviewToFront:yourButtonView]; 

推入你的所有其他視圖(也嵌入的)前您buttonView儘管如此,如上所述,這隻能解決症狀,但如果您想添加更多「重疊」元素,則必須爲所有這些元素執行此操作。更好的方式是:

還是編程方法: 添加您的UIButton編程方式而不是故事板添加的UIPageViewController的視圖到您的視圖層次之後。所以,你這樣做

[self.view addSubview:_pageViewController.view]; 

後只需實例化一個的UIButton您的配置,並通過

[self.view addSubview:yourProgrammaticallyCreatedButton]; 

添加或添加一個容器視圖< - 我的建議 添加另一種觀點認爲(我們可以稱之爲它的容器視圖),但不要將該按鈕添加到該容器視圖。給它一些限制,使其具有與你的觀點相同的框架。將IBOutlet保留爲UIView並使用此視圖添加UIPageViewControllers視圖。

_pageViewController.view.frame = self.containerView.bounds; 
[self.containerView addSubView: _pageViewController.view]