gpt4 book ai didi

ios - 自动水平滚动

转载 作者:行者123 更新时间:2023-11-29 00:15:22 24 4
gpt4 key购买 nike

我应该怎么做才能像应用商店一样自动水平滚动

会有一堆图像。这些图像有一些延迟出现在屏幕上并移出屏幕,这会无限重复,就像应用程序商店一样。

最佳答案

你可以用这个

https://github.com/evgenyneu/Auk

将此添加到您的 pod 文件中

   pod 'Auk', '~> 7.0'

运行 pod 安装

  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
}

在你的 View Controller 中

   import Auk

添加委托(delegate) UIScrollViewDelegate

    class yourViewController: UIViewController ,UIScrollViewDelegate 

拿一个 UIScrollView 做一个 outlet

           @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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com