UIPageViewController UIImage没有全屏显示 [英] UIPageViewController UIImage not showing full screen
问题描述
我正在创建一个tab-view控制器的应用程序。对于第一个选项卡,我有一个滚动图片的UIPageViewController。一切正常,除了图片没有全屏显示。我为图像视图设置了约束以覆盖整个视图控制器,但是当它被加载到页面视图中时,它不会一直覆盖到底部。图像被滚动点指示符切断,然后它只是白色。
I am making an application that is a tab-view controller. For the first tab, I have a UIPageViewController that is scrolling through pictures. Everything works properly, except for that the picture is not showing full screen. I have constraints set up for the image view to cover the whole view controller but when it gets loaded into the page view, it doesn't cover all the way to the bottom. The image gets cut off by the scrolling dot indicators and then it is just white.
我确定它很简单,但有没有一种方法可以覆盖图像全屏我喜欢设置限制吗?
I'm sure it is simple, but is there a way that the images will cover the full screen like I have the constraints set up to do?
推荐答案
该页面上有一个非常简单的解决方案: http://tunesoftware.com/?p=3363
There's quite a simple solution for this problem on that page: http://tunesoftware.com/?p=3363
通过覆盖的 viewDidLayoutSubviews 方法来完成UIPageViewController 基本上做了两件事:
It is done by overriding the viewDidLayoutSubviews method of UIPageViewController and basically doing two things:
- 增加 UIScrollView 的界限(内容)通过将其框架设置为t,在 UIPageViewController 内部页面控制器视图的界限
- 将 UIPageControl 元素(点)移动到视图层次结构的前面,使其位于内容的前面
- Increasing the bounds of the UIScrollView (the content) inside the UIPageViewController by setting it's frame to the bounds of the page controller's view
- Moving the UIPageControl element (the dots) to the front of the view hierarchy so that it's in front of the content
这是他提供的代码(如果链接被破坏):
Here's the code he provides (in case the link gets broken):
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!)
}
}
}
之后您需要做的就是:
- 如果您在故事板中设置页面控制器,那么只需转到身份检查器窗格并将其类更改为 TSPageViewController
- 如果您在代码中设置页面控制器,那么只需确保为其定义的类继承 TSPageViewController 类
- If you set your page controller in the storyboard, then just go to the identity inspector pane and change its class to TSPageViewController
- If you set your page controller in code, then just make sure the class you defined for it inherits the TSPageViewController class
干杯,
Joe
Cheers, Joe
这篇关于UIPageViewController UIImage没有全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!