我希望通过快速代码在我的照片显示应用中制作无限的Scrollview。 我可以找到像“scrollViewDidEndDragging:willDecelerate”这样的Object-c方法来启用它,但不能用于swift。这是我的代码,我尝试使用“scrollView.contentOffset.y”但不起作用。有人可以帮助实现这一目标吗? 我还在故事板中创建了UIScrollView。
import UIKit
class ViewController: UIViewController {
@IBOutlet var scrollView: UIScrollView!
scrollView.pagingEnabled = true
scrollView.scrollEnabled = true
scrollView.directionalLockEnabled = true
scrollView.showsHorizontalScrollIndicator = false
scrollView.showsVerticalScrollIndicator = true
scrollView.bounces = true
scrollView.scrollsToTop = false
self.scrollView.contentSize = CGSizeMake(620, 480*3);
self.navigationItem.titleView = pageControl
let imgarray2 = ["1446420031.jpg", "4500129.jpg", 475323.jpg"]
for (index, value) in enumerate(imgarray2) {
var setx = 0
var sety = index*480
var imgnum = index+1
let url = NSURL.URLWithString("\(value)");
var err: NSError?
var imageData :NSData = NSData.dataWithContentsOfURL(url,options: NSDataReadingOptions.DataReadingMappedIfSafe, error: &err)
var blueimage = UIImage(data:imageData)
var blueView = UIImageView(image: blueimage)
blueView.contentMode = UIViewContentMode.ScaleAspectFill
blueView.frame = CGRect(origin: CGPoint(x: setx, y: sety), size:blueimage.size)
scrollView.addSubview(blueView)
}
if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
self.scrollView.contentSize = CGSizeMake(620, 480*6);
for (index, value) in enumerate(imgarray2) {
var setx = 0
var sety = index*480+(480*3)
var imgnum = index+1
let url = NSURL.URLWithString("\(value)");
var err: NSError?
var imageData :NSData = NSData.dataWithContentsOfURL(url,options: NSDataReadingOptions.DataReadingMappedIfSafe, error: &err)
var blueimage = UIImage(data:imageData)
var blueView = UIImageView(image: blueimage)
blueView.contentMode = UIViewContentMode.ScaleAspectFill
blueView.frame = CGRect(origin: CGPoint(x: setx, y: sety), size:blueimage.size)
scrollView.addSubview(blueView)
}
}