参考:Scroll View Tutorial in iOS8 with Swift
知识点:UIScrollView
当视图超过屏幕大小时,可通过把视图放在UIScrollView
中让视图可以上下滚动的功能。以一张大图片为例。
- 新建项目 ScrollViewTutorial
- 代码:
class ViewController: UIViewController {
var imageView: UIImageView!
var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
imageView = UIImageView(image: UIImage(named: "strandvagen.jpg"))
scrollView = UIScrollView(frame: view.bounds)
scrollView.backgroundColor = UIColor.black
scrollView.contentSize = imageView.bounds.size
scrollView.addSubview(imageView)
view.addSubview(scrollView)
}
}
详细代码:ScrollViewTutorial