我正在面對Swift中的滾動視圖這個奇怪的問題,即使在定義文件中的滾動視圖後圖像也不滾動,我還添加了縮放並且它工作正常。請幫我這個 https://pastebin.com/1uC3fqHG無法在swift中使用滾動視圖滾動圖像
import UIKit
class ImageViewController: UIViewController
{
var imageURL: URL? {
didSet {
image = nil
if view.window != nil {
fetchImage()
}
}
}
private func fetchImage() {
if let url = imageURL {
let urlContents = try? Data(contentsOf: url)
if let imageData = urlContents {
image = UIImage(data: imageData)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
imageURL = URL(string: "http://www.lamborghini.com/en-en/sites/en-en/files/DAM/lamborghini/share%20img/huracan-coupe-facebook-og.jpg")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if image == nil {
fetchImage()
}
}
@IBOutlet weak var scrollView: UIScrollView! {
didSet {
scrollView.delegate = self
scrollView.minimumZoomScale = 0.03
scrollView.maximumZoomScale = 2.0
scrollView.contentSize = imageView.frame.size
scrollView.addSubview(imageView)
}
}
fileprivate var imageView = UIImageView()
private var image: UIImage? {
get{
return imageView.image
}
set{
imageView.image = newValue
imageView.sizeToFit()
scrollView?.contentSize = imageView.frame.size
}
}
}
extension ImageViewController: UIScrollViewDelegate
{
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return imageView
}
}
感謝很多:) –