UIPageViewController UIImage does not show full screen

I am creating an application that is a tab controller. For the first tab, I have a UIPageViewController that scrolls images. Everything works correctly, except that the image is not displayed in full screen mode. I have restrictions on the presentation of the image to cover the entire view controller, but when it is loaded into the page view, it does not cover the whole way to the bottom. The image is cropped by the scroll indicators, and then it's just white.

I am sure it is simple, but is there a way that images will cover the entire screen, how do I have restrictions set to execute?

As you can see, the image stops at the bottom where the dots begin. Where as I want it to go all the way down to the bottom. So the area with the dots is transparent.

+4
source share
2 answers

Here's a pretty simple solution to this problem: http://tunesoftware.com/?p=3363

This is done by overriding the viewDidLayoutSubviews UIPageViewController method and basically does two things:

  • Enlarges the borders of the UIScrollView (content) inside the UIPageViewController , setting its frame to the borders of the page manager view
  • Move the UIPageControl element (dots) to the front of the view hierarchy so that it is in front of the contents

Here is the code that it provides (in case of communication failure):

import UIKit class TSPageViewController: UIPageViewController { override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() var subViews: NSArray = view.subviews var scrollView: UIScrollView? = nil var pageControl: UIPageControl? = nil for view in subViews { if view.isKindOfClass(UIScrollView) { scrollView = view as? UIScrollView } else if view.isKindOfClass(UIPageControl) { pageControl = view as? UIPageControl } } if (scrollView != nil && pageControl != nil) { scrollView?.frame = view.bounds view.bringSubviewToFront(pageControl!) } } } 

All you have to do after this is:

  • If you installed your page controller in the storyboard, just go to the ID inspector panel and change your class to TSPageViewController
  • If you installed your page controller in your code, just make sure that the class you defined for it inherits the TSPageViewController class

Cheers, Joe

+6
source

Here is the version of Objective-C. Create a new class (2 files):

(1) BasePageViewController.h extends UIPageViewController

 #import <UIKit/UIKit.h> @interface BasePageViewController : UIPageViewController @end 

(2) BasePageViewController.m with viewDidLayoutSubviews overriding

 #import "BasePageViewController.h" @implementation BasePageViewController - (void) viewDidLayoutSubviews { [super viewDidLayoutSubviews]; UIScrollView *scrollView = nil; UIPageControl *pageControl = nil; for(UIView *view in self.view.subviews) { if([view isKindOfClass:[UIScrollView class]]) { scrollView = (UIScrollView *)view; }else if([view isKindOfClass:[UIPageControl class]]) { pageControl = (UIPageControl *)view; } } if(scrollView != nil && pageControl!=nil) { scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); [self.view bringSubviewToFront:pageControl]; } } @end 
+1
source

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


All Articles