作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用第三方进行循环 ScrollView ,一切都很完美。我唯一想要的是 ScrollView 应该自动滚动,以便图像应该每 15 秒后自动滚动一次。第三方链接:https://github.com/DroidsOnRoids/SwiftCarousel
最佳答案
问:我想问示例 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
}
}
这段代码使轮播自动滚动。
关于swift - 圆形 UIScrollView – SwiftCarousel : Want to autoscroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36306765/
我正在使用第三方进行循环 ScrollView ,一切都很完美。我唯一想要的是 ScrollView 应该自动滚动,以便图像应该每 15 秒后自动滚动一次。第三方链接:https://github.c
我是一名优秀的程序员,十分优秀!