All Projects → mengxianliang → Xlcardswitch

mengxianliang / Xlcardswitch

iOS 利用余弦函数特性实现可以居中放大的图片浏览工具

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Xlcardswitch

Drawer Behavior
Drawer behavior is a library that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide.
Stars: ✭ 394 (+9.14%)
Mutual labels:  scale, card
Reactnative Animation Challenges
A series of animation challenges in React Native.
Stars: ✭ 352 (-2.49%)
Mutual labels:  switch
Switch Desktop
⚡️ Keyboard-driven commands to navigate your apps faster
Stars: ✭ 320 (-11.36%)
Mutual labels:  switch
Horizontalpicker
A simple, customizable and easy to use picker where centre view is scaled up
Stars: ✭ 337 (-6.65%)
Mutual labels:  scale
Asscroll
Ash's Smooth Scroll 🍑
Stars: ✭ 324 (-10.25%)
Mutual labels:  scroll
Stacklayoutmanager
customized layoutmanager,let item pile up like stackview/类似最美有物卡片堆叠效果
Stars: ✭ 343 (-4.99%)
Mutual labels:  card
Nextcloud Deck
📋 Android client for nextcloud deck app
Stars: ✭ 318 (-11.91%)
Mutual labels:  card
Ngx Scrollbar
Custom overlay-scrollbars with native scrolling mechanism
Stars: ✭ 355 (-1.66%)
Mutual labels:  scroll
Ira Illustrations
Build your own amazing illustrations
Stars: ✭ 351 (-2.77%)
Mutual labels:  scale
Orionpreview
🅾️ OrionPreview is a simple animation with tanslation or scale views written in Java.
Stars: ✭ 335 (-7.2%)
Mutual labels:  scale
Flutter Infinitecards
An infinite card switching UI for Flutter, support custom animation 自定义实现神奇动效的卡片切换视图
Stars: ✭ 333 (-7.76%)
Mutual labels:  card
Vue Scrollama
Vue component to easily setup scroll-driven interactions (aka scrollytelling)
Stars: ✭ 326 (-9.7%)
Mutual labels:  scroll
Uos
🐭 A tiny 250b scroll listener with progress.
Stars: ✭ 349 (-3.32%)
Mutual labels:  scroll
Scale
🎏 Unit converter in Swift
Stars: ✭ 324 (-10.25%)
Mutual labels:  scale
Dragsloplayout
A UI library for Android
Stars: ✭ 354 (-1.94%)
Mutual labels:  scroll
Scrollmonitor
A simple and fast API to monitor elements as you scroll
Stars: ✭ 3,250 (+800.28%)
Mutual labels:  scroll
Mockolo
Efficient Mock Generator for Swift
Stars: ✭ 327 (-9.42%)
Mutual labels:  scale
Jump.js
A modern smooth scrolling library.
Stars: ✭ 3,459 (+858.17%)
Mutual labels:  scroll
Jquery.scrollto
Lightweight, cross-browser and highly customizable animated scrolling with jQuery
Stars: ✭ 3,609 (+899.72%)
Mutual labels:  scroll
Mfcard
Easily integrate Credit Card payments module in iOS App. Swift 4.0
Stars: ✭ 356 (-1.39%)
Mutual labels:  card

XLCardSwitch

利用余弦函数的曲线特性实现的图片居中放大浏览工具,内部是利用UICollectionview的滚动实现的,有兴趣的可以看一下我的博文,里面有具体的实现原理,还是挺好玩儿的。本工具也只是想传递这个这个居中放大的算法,为了方便使用也做了些功能性的封装;

功能

  • [x] 手指拖动切换卡片
  • [x] 调用方法切换卡片
  • [x] 可设置分页滚动

效果

正常滚动 自动居中 调用方法切换
image image image

使用方法

OC版本

创建方法:

    //设置卡片浏览器
    _cardSwitch = [[XLCardSwitch alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)];
    _cardSwitch.items = items;
    //设置代理
    _cardSwitch.delegate = self;
    //设置是否打开分页滑动
    _cardSwitch.pagingEnabled = true;
    //设置初始位置,默认为0
    _cardSwitch.selectedIndex = 3;
    [self.view addSubview:_cardSwitch];

切换位置:

[_cardSwitch switchToIndex:3 animated:true];

_cardSwitch.selectedIndex = 3;

代理方法:

- (void)XLCardSwitchDidSelectedAt:(NSInteger)index {
    NSLog(@"选中了:%zd",index);
}

Swift版本

1、创建

lazy var cardSwitch: XLCardSwitch = {
    let temp = XLCardSwitch.init()
    temp.frame = self.view.bounds
    temp.dataSource = self
    temp.delegate = self
    //注册cell
    temp.register(cellClass: CustomCollectionViewCell.self, forCellWithReuseIdentifier:"CustomCellID")
    return temp
}()

2、DataSource

注:使用时必须接入DataSource方法,且需要自定义一个UICollectionviewcell,使用方法和UICollectionview一样,先注册,再使用;XLCardSwitch只负责缩放效果,不关心其他数据和UI

//DataSource方法,返回总共卡片个数
func cardSwitchNumberOfCard() -> (Int) {
    return self.cellInfoArr().count
}
    
//DataSource方法,返回UICollectionViewCell
func cardSwitchCellForItemAtIndex(index: Int) -> (UICollectionViewCell) {
    let cell = self.cardSwitch.dequeueReusableCell(withReuseIdentifier:"CustomCellID", for: index) as! CustomCollectionViewCell
    cell.imageView.image = UIImage.init(named: self.cellInfoArr()[index].0)
    cell.textLabel.text = self.cellInfoArr()[index].1
    return cell
}

3、Delegate

//滑动切换到新的位置回调
@objc optional func cardSwitchDidScrollToIndex(index: Int) -> ()
//手动点击了
@objc optional func cardSwitchDidSelectedAtIndex(index: Int) -> ()

实现原理请参考我的博文

个人开发过的UI工具集合 XLUIKit

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].