FastNavigator
如何以编程方式制作滚动视图来解决此问题?
class FastNavigator: UIView {
var scrollView : UIScrollView!
var scrollSubviews : [UIView]!
var size :CGFloat = 0
func configure(subviews:[UIView]){
scrollSubviews = subviews
scrollView = UIScrollView(frame: self.frame)
self.addSubview(scrollView)
for view in scrollSubviews {
scrollView.addSubview(view)
view.frame = CGRect(x: 0 + size , y: 0, width: scrollView.frame.width, height: scrollView.frame.height)
size += view.frame.size.width
print(size)
}
scrollView.contentSize = CGSize(width: size, height: scrollView.frame.height)
}
}
的ViewController
class ViewController: UIViewController {
let fast = FastNavigator()
let myImages = ["mahmoud.jpg","ziad.jpg","farah.jpg","zinji.jpg"]
override func viewDidLoad() {
super.viewDidLoad()
var subViews : [UIImageView] = []
for imageName in myImages {
let myUIImage = UIImage(contentsOfFile: Bundle.main.path(forResource: imageName, ofType: "")!)
let imageView = UIImageView(image: myUIImage)
subViews.append(imageView)
}
fast.frame = self.view.frame
fast.configure(subviews: subViews)
self.view.addSubview(fast)
}
}
我总是得到这个
libc ++ abi.dylib:以NSException类型的未捕获异常终止