我应该如何像App Store一样自动水平滚动?
将有一堆图像。这些图像会稍有延迟地出现在屏幕上并移出,并且会无限重复,例如应用商店。
最佳答案
你可以用这个
https://github.com/evgenyneu/Auk
将此添加到您的pod文件
pod 'Auk', '~> 7.0'
运行pod install
import UIKit
struct DemoConstants {
static let button = DemoConstantsButton()
static let initialImage = (
fileName: "slider1.jpg",
description: " demo"
)
static let localImages = [
(
fileName: "image1.jpg",
description: "Hotel Nirvana"
),
(
fileName: "image2.jpg",
description: "Hotel Nirvana"
),
(
fileName: "image3.jpg",
description: "demo2"
),
(
fileName: "image4.jpg",
description: "demo3"
),
(
fileName: "image5.jpg",
description: "demo4"
),
(
fileName: "image6.jpg",
description: "demo5"
)]
}
struct DemoConstantsButton {
let borderWidth: CGFloat = 2
let cornerRadius: CGFloat = 20
let borderColor = UIColor.white
}
在您的视图控制器中
import Auk
添加委托UIScrollViewDelegate
class yourViewController: UIViewController ,UIScrollViewDelegate
拿一个UIScrollView并做一个出口
@IBOutlet weak var scrollView: UIScrollView!
在viewDidLoad中
scrollView.delegate = self
for localImage in DemoConstants.localImages {
if let image = UIImage(named: localImage.fileName) {
scrollView.auk.show(image: image)
}}
let pageIndex = scrollView.auk.currentPageIndex
print(pageIndex!)
scrollView.auk.settings.contentMode = UIViewContentMode.scaleAspectFill
scrollView.auk.settings.pagingEnabled = true
self.scrollView.auk.settings.pageControl.backgroundColor = UIColor.black
scrollView.auk.startAutoScroll(delaySeconds: 3)
scrollView.auk.scrollToPage(atIndex: 2, animated: true)
关于ios - 自动水平滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45413122/