【发布时间】:2016-03-30 10:56:26
【问题描述】:
我正在使用第三方进行循环滚动视图,一切都很完美。我唯一想要的是滚动视图应该自动滚动,以便图像应该在每 15 秒后自动滚动。第三方链接:https://github.com/DroidsOnRoids/SwiftCarousel
【问题讨论】:
标签: swift uiscrollview infinite-scroll pager autoscroll
我正在使用第三方进行循环滚动视图,一切都很完美。我唯一想要的是滚动视图应该自动滚动,以便图像应该在每 15 秒后自动滚动。第三方链接:https://github.com/DroidsOnRoids/SwiftCarousel
【问题讨论】:
标签: swift uiscrollview infinite-scroll pager autoscroll
问:我想在示例 2 中询问图像是否应该在每 15 秒后自动滚动一次?
答: 嘿!
我们没有内置方法,但您可以使用 NSTimer,它每 15 秒执行一次任务,该任务将使用方法 selectItem(:animated) 选择下一个项目。您还应该注意,您可能会尝试选择低于 0 的索引或高于轮播中项目数量的索引,因此您必须确保做出条件语句。
干杯!
我在上面的 SwiftCarousel 主页 (http://www.thedroidsonroids.com/blog/ios/circular-scroll-view-swiftcarousel/) 中找到。
编辑:
//declaring variables
var carouselTimer : NSTimer!
var counter = 0
//
//in viewDidLoad
carouselTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: #selector(selectIteminCarousel), userInfo: nil, repeats: true)
//
func selectIteminCarousel()
{
carousel.selectItem(counter, animated: true)
counter += 1
if counter > 2
{
self.counter = 0
}
}
这段代码使轮播自动滚动。
【讨论】: