Swift UIScrollView - 奇怪的填充
Swift UIScrollView - strange padding
我需要让花朵图像翻转。图像必须具有相同的高度,但自动设置宽度。我想让他们左右滚动
这是我的代码:
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
var images = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
for i in 1...3 {
images.append(UIImage(named: "bild-0\(i).jpg")!)
}
var i: CGFloat = 0
var origin: CGFloat = 0
let height: CGFloat = scrollView.bounds.height
for image in images {
let imageView = UIImageView(frame: CGRectZero)
imageView.frame.size.height = height
imageView.image = image
imageView.sizeToFit()
imageView.frame.origin.x = origin
println(imageView.frame.size.width)
println(imageView.frame.origin.x)
println(imageView.frame.size.height)
println("asd")
origin = origin + imageView.frame.size.width
i++
scrollView.addSubview(imageView)
}
scrollView.contentSize.width = origin
scrollView.bounces = false
scrollView.pagingEnabled = false
}
}
故事板:
问题(从顶部填充!- 红色 - 是 UIScrollView 的背景):
图片为 765x510 300x510 等等
UIScrollView 高度为 170
这是由滚动插图引起的:
在 Storyboard 上单击您的 ViewController 并转到文件检查器,您应该会看到此对话框:
取消选中“调整滚动视图插图”。
我需要让花朵图像翻转。图像必须具有相同的高度,但自动设置宽度。我想让他们左右滚动 这是我的代码:
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
var images = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
for i in 1...3 {
images.append(UIImage(named: "bild-0\(i).jpg")!)
}
var i: CGFloat = 0
var origin: CGFloat = 0
let height: CGFloat = scrollView.bounds.height
for image in images {
let imageView = UIImageView(frame: CGRectZero)
imageView.frame.size.height = height
imageView.image = image
imageView.sizeToFit()
imageView.frame.origin.x = origin
println(imageView.frame.size.width)
println(imageView.frame.origin.x)
println(imageView.frame.size.height)
println("asd")
origin = origin + imageView.frame.size.width
i++
scrollView.addSubview(imageView)
}
scrollView.contentSize.width = origin
scrollView.bounces = false
scrollView.pagingEnabled = false
}
}
故事板:
问题(从顶部填充!- 红色 - 是 UIScrollView 的背景):
图片为 765x510 300x510 等等 UIScrollView 高度为 170
这是由滚动插图引起的:
在 Storyboard 上单击您的 ViewController 并转到文件检查器,您应该会看到此对话框:
取消选中“调整滚动视图插图”。