我正在实现一个简单的图库视图控制器,其中应用程序显示用户可以滚动的一小部分全屏图像.我正在使用UIPageViewController,我认为,如果我实现了正确的数据源函数,它应该自动显示页面控制指示器.但是我仍然看不到任何指标.
在我的主要GalleryViewController
:
class GalleryViewController: UIViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
var pageController: UIPageViewController?
var pageContent = NSArray()
override func viewDidLoad() {
super.viewDidLoad()
.... some code to load images into the pageContent array ....
pageController = UIPageViewController(transitionStyle:.Scroll, navigationOrientation:.Horizontal,options:nil)
pageController?.delegate = self
pageController?.dataSource = self
... some more standard code to add the page controller to self.view etc.
var pageControl = UIPageControl.appearance()
pageControl.pageIndicatorTintColor = UIColor.lightGray()
pageControl.currentPageIndicatorTintColor = UIColor.whiteColor()
pageControl.backgroundColor = UIColor.blackColor()
pageController!.didMoveToParentViewController(self)
}
func viewControllerAtIndex(index:Int) -> ContentViewController? {
....
}
Run Code Online (Sandbox Code Playgroud)
我已经实现了两个必需的协议方法viewControllerBeforeViewController和viewControllerAfterController以及两个必需的分页方法,presentationCountForPagesViewController和presentationIndexForPageViewController.
我 …
我仍然试图在XCode 6.3中了解Swift Autolayouts.我已经设置了一个View Controller,我在Interface Builder中粘贴了几个标签.我已经以编程方式添加了UITextView和UIImageView,并且我尝试在屏幕底部添加UIButton并以编程方式设置其约束.但是,当视图尝试加载时,我不断收到错误.
根据类定义:
let infoButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
var descView: UITextView!
var picView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
infoButton.setTranslatesAutoresizingMaskIntoConstraints(false)
infoButton.setTitle("Information",forState:UIControlState.Normal)
self.view.addSubview(infoButton)
self.descView = UITextView(frame:CGRectMake(0,0,300,290))
self.descView.selectable = false
self.userInteractionEnabled = false
self.descView.text = "testing block of text"
self.container.frame = CGRect(x:20,y:160,width:300,height:290)
self.picView = UIImageView(image:"house.png")
self.view.addSubview(container)
self.container.addSubview(picView)
//setup button constraints
let viewsDictionary = ["infoButton":infoButton]
let button_constraint_H:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[infoButton]-|", options:NSLayoutFormatOptions(0),metrics:nil,views:viewsDictionary)
let button_constraint_V:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:[infoButton]-0-|",options:NSLayoutFormatOptions(0),metrics:nil, views:viewsDictionary)
infoButton.addConstraints(button_constraint_H)
infoButton.addConstraints(button_constraint_V)
}
Run Code Online (Sandbox Code Playgroud)
该应用程序在viewDidLoad()方法中崩溃.
2015-06-17 16:59:14.902 LayoutTest[20323:5937743] The view hierarchy is not prepared for …
Run Code Online (Sandbox Code Playgroud)