Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

UIPageViewController within a UINavigationController

$
0
0

I have a UINavigationController which contains a UIPageViewController. This works alright except for one problem that seems to have to do with the NavigationBar. (This didn't happen when I had it hidden, but have since wanted to make it visible.) On the very first page of the UIPageViewController, there is some extra space at the top of the Subviews. The strangest thing to me is that if I click once on the screen, it pops back up to where it should be. All of the other pages appear fine. I wonder if it has something to do with the fact that when that first ViewController is loaded, the entire UIPageViewController has not yet been added to the UINavigationController. But I haven't had any luck fixing it. I wrote a small program to demonstrate.

Another oddity: Below, I create the UIPageViewController with UIPageViewControllerTransitionStyle.Scroll. If I use UIPageViewControllerTransitionStyle.PageCurl the bug does not repro.

Has anyone seen this behavior before? Thanks!

Cristina

public partial class AppDelegate : UIApplicationDelegate
    {
        UIWindow window;

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            // If this is set to PageCurl, it doesn't have the same problem. 
            var pageViewController = new UIPageViewController(UIPageViewControllerTransitionStyle.Scroll,   UIPageViewControllerNavigationOrientation.Horizontal, UIPageViewControllerSpineLocation.None, 0);
            pageViewController.SetViewControllers(new [] { new MessageViewController() }, UIPageViewControllerNavigationDirection.Forward, true, null);
            pageViewController.DataSource = new MessageDataSource();
            var navigationController = new UINavigationController(pageViewController);

            window.RootViewController = navigationController;

            window.MakeKeyAndVisible();

            return true;
        }
    }

    public class MessageDataSource : UIPageViewControllerDataSource
    {
        public override UIViewController GetNextViewController(UIPageViewController pageViewController, UIViewController referenceViewController)
        {
            return new MessageViewController();
        }

        public override UIViewController GetPreviousViewController(UIPageViewController pageViewController, UIViewController referenceViewController)
        {
            return new MessageViewController();
        }
    }

    public class MessageViewController : UIViewController
    {
        public override void ViewDidLoad()
        {
            var label = new UILabel 
            { 
                Text = "Check my y position", 
                Frame = new RectangleF(20, 84, 0, 0),
            };
            label.SizeToFit();

            this.View.BackgroundColor = UIColor.White;
            this.View.AddSubview(label);
        }
    }

Viewing all articles
Browse latest Browse all 204402


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>