Make a full-screen image view in the field of view of the page view controller / controller (fast)

I use the UIPageViewController to display images in full screen. The problem is that the images are not displayed in full screen. Instead, the bottom is the gap between the images and the viewpoints of the page and the top. I have a UIViewController that is added to the UIPageController as a child / child, and that the ViewController has images displayed using ImageView. I am trying to do this in a quick / storyboard.

I change the top panel and the bottom panel to "none" in the storyboard, but this did not work.

Image Preview:

enter image description here

ChildViewControllerCode Code:

class BoatContentViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! @IBOutlet weak var titleLabel: UILabel! var pageIndex: Int! var titleText: String! var imageFile: String! override func viewDidLoad() { super.viewDidLoad() self.imageView.image = UIImage(named: self.imageFile) self.titleLabel.text = self.titleText // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } 

Main control screen:

 class BoatViewController: UIViewController, UIPageViewControllerDataSource { @IBOutlet weak var loginButton: UIButton! @IBOutlet weak var skipButton: UIButton! var pageViewController: UIPageViewController! var pageTitles: NSArray! var pageImages: NSArray! override func viewDidLoad() { super.viewDidLoad() loginButton.backgroundColor = UIColor.clearColor() loginButton.layer.cornerRadius = 5 loginButton.layer.borderWidth = 1 loginButton.layer.borderColor = UIColor.purpleColor().CGColor skipButton.backgroundColor = UIColor.whiteColor() skipButton.layer.cornerRadius = 5 skipButton.layer.borderWidth = 1 skipButton.layer.borderColor = UIColor.whiteColor().CGColor self.pageTitles = NSArray(objects: "", "", "", "", "") self.pageImages = NSArray(objects: "onboarding1", "onboarding2", "onboarding3", "onboarding4", "onboarding5") self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("BoatPageViewController") as! UIPageViewController self.pageViewController.dataSource = self var startVC = self.viewControllerAtIndex(0) as BoatContentViewController var viewControllers = NSArray(object: startVC) self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: .Forward, animated: true, completion: nil) self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.size.height - 60) self.addChildViewController(self.pageViewController) self.view.addSubview(self.pageViewController.view) self.pageViewController.didMoveToParentViewController(self) // Do any additional setup after loading the view. } func viewControllerAtIndex(index: Int) -> BoatContentViewController { if ((self.pageTitles.count == 0) || (index >= self.pageTitles.count)) { return BoatContentViewController() } var vc: BoatContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("BoatContentViewController") as! BoatContentViewController vc.imageFile = self.pageImages[index] as! String vc.titleText = self.pageTitles[index]as! String vc.pageIndex = index return vc } func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? { var vc = viewController as! BoatContentViewController var index = vc.pageIndex as Int if (index == 0 || index == NSNotFound) { return nil } index-- return self.viewControllerAtIndex(index) } func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? { var vc = viewController as! BoatContentViewController var index = vc.pageIndex as Int if (index == NSNotFound) { return nil } index++ if (index == self.pageTitles.count) { return nil } return self.viewControllerAtIndex(index) } func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { return self.pageTitles.count } func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int { return 0 } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } 

Application Delegate:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. var pageControl = UIPageControl.appearance() pageControl.pageIndicatorTintColor = UIColor.lightGrayColor() pageControl.currentPageIndicatorTintColor = UIColor.blackColor() pageControl.backgroundColor = UIColor.clearColor() return true } 
+6
source share
2 answers

The UIPageViewController has a view in which its pages will be displayed. These pages cannot be larger than this view β€” in other words, they are inside the page view controller.

Your UIPageViewController is smaller than the screen β€” it allows you to control the page and button at the bottom of the screen, and the navigation bar at the top. You yourself make it be true:

 self.pageViewController.view.frame = CGRectMake(0, 30, self.view.frame.width, self.view.frame.size.height - 60) 

You allowed a gap of 30 points at the top and a 30 percent gap at the bottom. Thus, the images that he displays can never be larger. They can never be full-screen.

+2
source

Swift 3 version when subclassing UIPageViewController:

 override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() let subViews: NSArray = view.subviews as NSArray var scrollView: UIScrollView? = nil var pageControl: UIPageControl? = nil for view in subViews { if view is UIScrollView { scrollView = view as? UIScrollView } else if view is UIPageControl { pageControl = view as? UIPageControl } } if (scrollView != nil && pageControl != nil) { scrollView?.frame = view.bounds view.bringSubview(toFront: pageControl!) } } 
0
source

Source: https://habr.com/ru/post/989291/


All Articles