All Projects → dulingkang → SSCycleScrollView

dulingkang / SSCycleScrollView

Licence: MIT license
轮播终结者,用swift完成,易用集成

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Labels

Projects that are alternatives of or similar to SSCycleScrollView

vue-scroll-lock
一个 VUE 组件:子元素 scroll 父元素容器不跟随滚动(兼容PC、移动端)
Stars: ✭ 31 (-20.51%)
Mutual labels:  scroll
use-smooth-scroll
React hook which gives a smooth scrolling function.
Stars: ✭ 41 (+5.13%)
Mutual labels:  scroll
chrome-mouse-wheel-tab-scroller
Scroll Google Chrome tabs using mouse wheel
Stars: ✭ 39 (+0%)
Mutual labels:  scroll
react-smart-scroll
Efficient rendering of long lists in React
Stars: ✭ 27 (-30.77%)
Mutual labels:  scroll
kubernetes-scheduling-examples
Walk-through guide of advanced scheduling concepts in Kubernetes
Stars: ✭ 38 (-2.56%)
Mutual labels:  pod
vue-scrollin
🎰 Scroll-in text component for Vue
Stars: ✭ 61 (+56.41%)
Mutual labels:  scroll
simple-scrollspy
Simple scrollspy without jQuery, no dependencies
Stars: ✭ 53 (+35.9%)
Mutual labels:  scroll
EasyScrollDots
Single page scroll JavaScript plugin that allows for vertical navigation of page sections
Stars: ✭ 38 (-2.56%)
Mutual labels:  scroll
scrolltotop
Scroll To Top extension for Chrome, Firefox, Safari, Opera.
Stars: ✭ 60 (+53.85%)
Mutual labels:  scroll
scrollbounce
Add a subtle bounce effect on mobile when the user scrolls (WIP)
Stars: ✭ 17 (-56.41%)
Mutual labels:  scroll
react-scrolling-color-background
background with color transitioning as you scroll, declarative and easy to setup
Stars: ✭ 53 (+35.9%)
Mutual labels:  scroll
QuickWebKit
A great & strong plugin based WebViewController. 一款基于插件的 WebView 视图控制器,您可以基于它设计您的浏览器插件,然后像积木一样来组装它们。
Stars: ✭ 29 (-25.64%)
Mutual labels:  pod
really-smooth-scroll
A script that smoothen scrolling in the browser
Stars: ✭ 21 (-46.15%)
Mutual labels:  scroll
simplenetes
The sns tool is used to manage the full life cycle of your Simplenetes clusters. It integrates with the Simplenetes Podcompiler project podc to compile pods.
Stars: ✭ 731 (+1774.36%)
Mutual labels:  pod
angular2-infinite-scroll
Infinite Scroll Directive For Angular (version 2 up to 2.3.1)
Stars: ✭ 16 (-58.97%)
Mutual labels:  scroll
kubernetes-basico
Demonstração dos componentes do Kubernetes
Stars: ✭ 26 (-33.33%)
Mutual labels:  pod
GQImageVideoViewer
仿微信多图片及视频浏览器,图片和视频原尺寸显示,不会变形,双击图片放大缩小,单击消失,支持多张本地和网络图片以及网络视频混合查看,支持链式调用
Stars: ✭ 57 (+46.15%)
Mutual labels:  pod
slider-manager
simple wrapper to create sliders focused on animations
Stars: ✭ 28 (-28.21%)
Mutual labels:  scroll
CXDatePickerView
一个自定义的日期时间选择器
Stars: ✭ 62 (+58.97%)
Mutual labels:  pod
scrollpup.js
Minimal beautiful bar to show scroll progress. Pure Javascript Plugin.MIT
Stars: ✭ 83 (+112.82%)
Mutual labels:  scroll

swift首页轮播 轻量级

  • 轮播终结者,用swift完成,易于集成使用,下载图片使用了SDWebImage
  • 自己动手用swift写了一个,欢迎试用!
  • 效果图:

网上找了一些首页轮播,写的或多或少有一些问题,用着不舒服,自己用swift写了一个轮播控件,有如下特点:

  • 下载图片使用了SDWebImage,性能高
  • 轮播图上需要点击链接,只需要调用一个block便可加上点击,易于集成
  • 支持webp格式图片,由于加入支持webp,电脑需要翻墙才能安装,电脑更改hosts在这儿

使用方法

在Podfile加入以下:

use_frameworks!
pod 'SSCycleScrollView'

这个库中支持了webp格式图片,引入了SDWebImage库。 下面可参考Demo中: 初始化时,传一个url的array,可以传本地的图片名字,也可以传网络图片; v2.1.0中为了引入网络图片的placeholderImage,此array改成了如下样式:

var scrollImageUrls: [[String]] {
        get {
            return [["https://devthinking.com/images/wechatqcode.jpg", "banner4.jpg"],
                    ["banner1.jpg"],
                    ["banner3.jpg"]]
        }
    }

初始化一个SSCycleScrollView:

        self.mainScrollView = SSCycleScrollView.init(frame: currentRect, animationDuration: 3, inputImageUrls: self.scrollImageUrls)
        self.mainScrollView?.tapBlock = {index in
            print("tapped page\(index)")
        }

autoScroll默认为true,如只需要手动滚动,需要:

       self.mainScrollView?.autoScroll = false

原理SSCycleScrollView

初始化后会启动一个定时器,repeat调用一个timerFired方法,方法中每次对scrollview加一个自己宽度的offset:

func timerFired() {
let xOffset = Int(self.contentOffset.x/kScreenWidth)
let xOffsetFloat = CGFloat(xOffset) * kScreenWidth
let newOffset = CGPointMake(xOffsetFloat + CGRectGetWidth(self.frame), self.contentOffset.y)
self.setContentOffset(newOffset, animated: true)
}

没有直接加xOffset, 而是对其做了一个换算,确保每次加的offset是自己宽度的整数倍。 在scrollViewDidScroll方法,每次计算前一个,当前,后一个index,确保index范围为index >= 0 && index < allImageArray.count, 每次滚动后都会三个imageView中的image做重新赋值:

self.previousDisplayView?.image = self.allImageArray[previousArrayIndex]
self.currentDisplayView?.image = self.allImageArray[self.currentArrayIndex]
self.lastDisplayView?.image = self.allImageArray[lastArrayIndex]
self.contentOffset = CGPointMake(CGRectGetWidth(self.frame), 0)

上面最后一行设置contenOffset非常重要,每次把scrollView的位置重置为1个自身宽度的offset。

小结

如果你觉得有不好的地方,可以提出来,大家一块研究一下,欢迎常来我的仓库,别忘记给个star!

微信公众号

开发者思维 devthinking

QQ交流群:295976280

iOS交流群(一)群二维码
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].