UIView -- How do I insert a UIView behind another view?

TrevorYokumTrevorYokum USMember ✭✭

Got a question for you guys. In my program, I have a UIPageViewController that is added as a child view controller via this.NavigationController.AddChildViewController(pvController) and is added as a subview of my current View via View.AddSubview(pvController.View)

I have added a transition to my View such that it slides down on the Y axis by 250 units:

        UIView.Transition(this.View, 1.5, UIViewAnimationOptions.CurveEaseOut, () =>
        {
            this.View.Frame = animateTo;
        }, null);

I want another UIView to be behind the UIPageViewController.View such that when I trigger my transition, the other view seems to slide into place. The problem is, I've tried so many various ways to do this to no avail. Here are all of the ways that I've tried to do this thus far:

    View.SendSubviewToBack(behind);
    pvController.View.InsertSubviewBelow(behind, pvController.View);
    pvController.View.InsertSubviewAbove(behind, pvController.View);
    pvController.View.SendSubviewToBack(behind);

I've gone as far as to try this:

View.InsertSubview(pvController.View, 0) //in place of View.AddSubview(pvController.View)
View.InsertSubview(behind, 1)

Yet, the UIView behind still shows up above the pvController.View

They all result in the same thing: the UIView behind is displayed above the pvController.View

Anyone have any ideas? Help is much appreciated!

Best Answer

  • TrevorYokumTrevorYokum US ✭✭
    Accepted Answer

    Got it!

    Instead of trying any fancy way of doing it or doing it in any strange order, I just did this:

    View.AddSubview(pvController.View);
    View.AddSubview(behind);
    View.SendSubviewToBack(behind);
    

    And I'm looking at the beginnings of a nicely animated menu. Thanks guys!

Answers

  • TrevorYokumTrevorYokum USMember ✭✭
    Accepted Answer

    Got it!

    Instead of trying any fancy way of doing it or doing it in any strange order, I just did this:

    View.AddSubview(pvController.View);
    View.AddSubview(behind);
    View.SendSubviewToBack(behind);
    

    And I'm looking at the beginnings of a nicely animated menu. Thanks guys!

Sign In or Register to comment.