我有那段代码:
import UIKit
class ProjectsViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var pageControlBookChapters: UIPageControl!
@IBOutlet weak var scrollViewBookChapters: UIScrollView!
@IBOutlet weak var contentsImageView: UIImageView!
@IBOutlet weak var contentsTextLabel: UILabel!
@IBOutlet weak var contentsLabel: UILabel!
@IBOutlet weak var projectName: UILabel!
@IBOutlet weak var projectImageView: UIImageView!
var page = 0
let arrImages : [String] = ["Captura1.jpg", "captura 2.jpg", "captura 3.jpg", "captura 4.jpg", "captura 5.jpg"];
override func viewDidLoad() {
super.viewDidLoad()
self.createHelpView()
pageControlBookChapters.backgroundColor = UIColor.clearColor()
pageControlBookChapters.pageIndicatorTintColor = UIColor.lightGrayColor()
pageControlBookChapters.currentPageIndicatorTintColor = UIColor(red: 251/255, green: 108/255, blue: 108/255, alpha: 1.0)
pageControlBookChapters.tintAdjustmentMode = UIViewTintAdjustmentMode.Dimmed
pageControlBookChapters.numberOfPages = arrImages.count
pageControlBookChapters.currentPage = 0
scrollViewBookChapters.scrollEnabled = true
scrollViewBookChapters.alwaysBounceHorizontal = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func createHelpView() {
var x = 50
for var i=0; i<arrImages.count; i++ {
var imgView = UIImageView(frame: CGRectMake(CGFloat(x), 50, CGFloat(scrollViewBookChapters.frame.width-100), CGFloat(scrollViewBookChapters.frame.height-150)))
imgView.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin
imgView.backgroundColor = UIColor.clearColor()
imgView.image = UIImage(named: arrImages[i])
imgView.contentMode = UIViewContentMode.ScaleAspectFit
scrollViewBookChapters.addSubview(imgView)
x = x + Int(scrollViewBookChapters.frame.width)
}
scrollViewBookChapters.contentSize = CGSizeMake(CGFloat(arrImages.count)*self.view.frame.width, 0)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
var pageWidth = CGFloat(scrollViewBookChapters.frame.width)
var fractionalPage = scrollViewBookChapters.contentOffset.x / pageWidth
page = lround(CDouble(fractionalPage))
pageControlBookChapters.currentPage = page
}
}
这正确地创建了scrollview和页面控件的点,但是当我尝试滚动它时,它不会移动,只显示要滚动的行,但即使我点击点按钮它也没有做任何事情。有什么不对吗?我甚至宣布scrollEnabled
并水平弹跳以强制它,但没有任何反应。
我已经检查了contentSize
并且似乎正常工作。