├── README.md ├── XLCardSwitchDemo ├── Resource │ └── DataPropertyList.plist ├── XLCardSwitch │ ├── XLCardCell.h │ ├── XLCardCell.m │ ├── XLCardModel.h │ ├── XLCardModel.m │ ├── XLCardSwitch.h │ ├── XLCardSwitch.m │ ├── XLCardSwitchFlowLayout.h │ └── XLCardSwitchFlowLayout.m ├── XLCardSwitchDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── Apple.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ ├── MengXianLiang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mxl.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── Apple.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ ├── XLCardSwitchDemo.xcscheme │ │ │ └── xcschememanagement.plist │ │ ├── MengXianLiang.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ ├── XLCardSwitchDemo.xcscheme │ │ │ └── xcschememanagement.plist │ │ └── mxl.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── XLCardSwitchDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── TestImages │ │ ├── 1.imageset │ │ ├── 1.png │ │ └── Contents.json │ │ ├── 10.imageset │ │ ├── 10.png │ │ └── Contents.json │ │ ├── 11.imageset │ │ ├── 11.png │ │ └── Contents.json │ │ ├── 12.imageset │ │ ├── 12.png │ │ └── Contents.json │ │ ├── 13.imageset │ │ ├── 13.png │ │ └── Contents.json │ │ ├── 2.imageset │ │ ├── 2.png │ │ └── Contents.json │ │ ├── 3.imageset │ │ ├── 3.png │ │ └── Contents.json │ │ ├── 4.imageset │ │ ├── 4.png │ │ └── Contents.json │ │ ├── 5.imageset │ │ ├── 5.png │ │ └── Contents.json │ │ ├── 6.imageset │ │ ├── 6.png │ │ └── Contents.json │ │ ├── 7.imageset │ │ ├── 7.png │ │ └── Contents.json │ │ ├── 8.imageset │ │ ├── 8.png │ │ └── Contents.json │ │ ├── 9.imageset │ │ ├── 9.png │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── DemoViewController.h │ ├── DemoViewController.m │ ├── Info.plist │ └── main.m └── XLCardSwitchExample-Swift ├── XLCardSwitch └── XLCardSwitch.swift ├── XLCardSwitchExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ ├── MengXianLiang.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── mxl.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── MengXianLiang.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ └── xcschememanagement.plist │ └── mxl.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── XLCardSwitchExample ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── TestImages │ │ ├── 1.imageset │ │ ├── 1.png │ │ └── Contents.json │ │ ├── 10.imageset │ │ ├── 10.png │ │ └── Contents.json │ │ ├── 11.imageset │ │ ├── 11.png │ │ └── Contents.json │ │ ├── 12.imageset │ │ ├── 12.png │ │ └── Contents.json │ │ ├── 13.imageset │ │ ├── 13.png │ │ └── Contents.json │ │ ├── 2.imageset │ │ ├── 2.png │ │ └── Contents.json │ │ ├── 3.imageset │ │ ├── 3.png │ │ └── Contents.json │ │ ├── 4.imageset │ │ ├── 4.png │ │ └── Contents.json │ │ ├── 5.imageset │ │ ├── 5.png │ │ └── Contents.json │ │ ├── 6.imageset │ │ ├── 6.png │ │ └── Contents.json │ │ ├── 7.imageset │ │ ├── 7.png │ │ └── Contents.json │ │ ├── 8.imageset │ │ ├── 8.png │ │ └── Contents.json │ │ ├── 9.imageset │ │ ├── 9.png │ │ └── Contents.json │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CustomCollectionViewCell.swift ├── Info.plist └── ViewController.swift ├── XLCardSwitchExampleTests ├── Info.plist └── XLCardSwitchExampleTests.swift └── XLCardSwitchExampleUITests ├── Info.plist └── XLCardSwitchExampleUITests.swift /README.md: -------------------------------------------------------------------------------- 1 | # XLCardSwitch 2 | 3 | 利用余弦函数的曲线特性实现的图片居中放大浏览工具,内部是利用UICollectionview的滚动实现的,有兴趣的可以看一下我的博文,里面有具体的实现原理,还是挺好玩儿的。本工具也只是想传递这个这个居中放大的算法,为了方便使用也做了些功能性的封装; 4 | 5 | ## 功能 6 | 7 | - [x] 手指拖动切换卡片 8 | - [x] 调用方法切换卡片 9 | - [x] 可设置分页滚动 10 | 11 | ## 效果 12 | 13 | |正常滚动|自动居中|调用方法切换| 14 | |:---:|:---:|:---:| 15 | |![image](https://github.com/mengxianliang/ImageRepository/blob/master/XLCardSwitch/GIF/1.gif)|![image](https://github.com/mengxianliang/ImageRepository/blob/master/XLCardSwitch/GIF/2.gif)|![image](https://github.com/mengxianliang/ImageRepository/blob/master/XLCardSwitch/GIF/3.gif)| 16 | 17 | ## 使用方法 18 | 19 | ### OC版本 20 | 21 | **创建方法:** 22 | 23 | ```objc 24 | //设置卡片浏览器 25 | _cardSwitch = [[XLCardSwitch alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)]; 26 | _cardSwitch.items = items; 27 |    //设置代理 28 |    _cardSwitch.delegate = self; 29 |    //设置是否打开分页滑动 30 |    _cardSwitch.pagingEnabled = true; 31 | //设置初始位置,默认为0 32 | _cardSwitch.selectedIndex = 3; 33 | [self.view addSubview:_cardSwitch]; 34 | ``` 35 | 36 | **切换位置:** 37 | 38 | ```objc 39 | [_cardSwitch switchToIndex:3 animated:true]; 40 | ``` 41 | 或 42 | ```objc 43 | _cardSwitch.selectedIndex = 3; 44 | ``` 45 | 46 | **代理方法:** 47 | 48 | ```objc 49 | - (void)XLCardSwitchDidSelectedAt:(NSInteger)index { 50 | NSLog(@"选中了:%zd",index); 51 | } 52 | ``` 53 | 54 | ### Swift版本 55 | 56 | 57 | #### 1、创建 58 | 59 | ```swift 60 | lazy var cardSwitch: XLCardSwitch = { 61 | let temp = XLCardSwitch.init() 62 | temp.frame = self.view.bounds 63 | temp.dataSource = self 64 | temp.delegate = self 65 | //注册cell 66 | temp.register(cellClass: CustomCollectionViewCell.self, forCellWithReuseIdentifier:"CustomCellID") 67 | return temp 68 | }() 69 | ``` 70 | 71 | #### 2、DataSource 72 | 73 | *注:使用时必须接入DataSource方法,且需要自定义一个UICollectionviewcell,使用方法和UICollectionview一样,先注册,再使用;XLCardSwitch只负责缩放效果,不关心其他数据和UI* 74 | 75 | ```swift 76 | //DataSource方法,返回总共卡片个数 77 | func cardSwitchNumberOfCard() -> (Int) { 78 | return self.cellInfoArr().count 79 | } 80 | 81 | //DataSource方法,返回UICollectionViewCell 82 | func cardSwitchCellForItemAtIndex(index: Int) -> (UICollectionViewCell) { 83 | let cell = self.cardSwitch.dequeueReusableCell(withReuseIdentifier:"CustomCellID", for: index) as! CustomCollectionViewCell 84 | cell.imageView.image = UIImage.init(named: self.cellInfoArr()[index].0) 85 | cell.textLabel.text = self.cellInfoArr()[index].1 86 | return cell 87 | } 88 | ``` 89 | 90 | #### 3、Delegate 91 | 92 | ```swift 93 | //滑动切换到新的位置回调 94 | @objc optional func cardSwitchDidScrollToIndex(index: Int) -> () 95 | //手动点击了 96 | @objc optional func cardSwitchDidSelectedAtIndex(index: Int) -> () 97 | ``` 98 | 99 | ### 实现原理请参考[我的博文](http://blog.csdn.net/u013282507/article/details/54136812) 100 | 101 | ### 个人开发过的UI工具集合 [XLUIKit](https://github.com/mengxianliang/XLUIKit) 102 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/Resource/DataPropertyList.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | title 7 | 艾德·史塔克 8 | imageName 9 | 1.png 10 | 11 | 12 | title 13 | 凯瑟琳·徒利·史塔克 14 | imageName 15 | 2.png 16 | 17 | 18 | title 19 | 罗柏·史塔克 20 | imageName 21 | 3.png 22 | 23 | 24 | title 25 | 琼恩·雪诺 26 | imageName 27 | 4.png 28 | 29 | 30 | title 31 | 艾莉亚·史塔克 32 | imageName 33 | 5.png 34 | 35 | 36 | title 37 | 珊莎·史塔克 38 | imageName 39 | 6.png 40 | 41 | 42 | title 43 | 布兰·史塔克 44 | imageName 45 | 7.png 46 | 47 | 48 | title 49 | 瑟曦·兰尼斯特·拜拉席恩 50 | imageName 51 | 8.png 52 | 53 | 54 | title 55 | 提利昂·兰尼斯特 56 | imageName 57 | 9.png 58 | 59 | 60 | title 61 | 泰温·兰尼斯特 62 | imageName 63 | 10.png 64 | 65 | 66 | title 67 | 詹姆·兰尼斯特 68 | imageName 69 | 11.png 70 | 71 | 72 | title 73 | 乔佛里·拜拉席恩 74 | imageName 75 | 12.png 76 | 77 | 78 | title 79 | 丹尼莉丝·坦格利安 80 | imageName 81 | 13.png 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // Card.h 3 | // CardSwitchDemo 4 | // 5 | // Created by Apple on 2016/11/9. 6 | // Copyright © 2016年 Apple. All rights reserved. 7 | // 被切换的卡片 8 | 9 | #import 10 | #import "XLCardModel.h" 11 | 12 | @interface XLCardCell : UICollectionViewCell 13 | 14 | @property (nonatomic, strong) XLCardModel *model; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // Card.m 3 | // CardSwitchDemo 4 | // 5 | // Created by Apple on 2016/11/9. 6 | // Copyright © 2016年 Apple. All rights reserved. 7 | // 8 | 9 | #import "XLCardCell.h" 10 | #import "XLCardModel.h" 11 | 12 | @interface XLCardCell () 13 | 14 | @property (nonatomic, strong) UIImageView *imageView; 15 | 16 | @property (nonatomic, strong) UILabel *textLabel; 17 | 18 | @end 19 | 20 | @implementation XLCardCell 21 | 22 | - (instancetype)initWithFrame:(CGRect)frame { 23 | if (self = [super initWithFrame:frame]) { 24 | [self buildUI]; 25 | } 26 | return self; 27 | } 28 | 29 | - (void)buildUI { 30 | self.layer.cornerRadius = 10.0f; 31 | self.layer.masksToBounds = true; 32 | self.backgroundColor = [UIColor whiteColor]; 33 | 34 | CGFloat labelHeight = self.bounds.size.height * 0.20f; 35 | CGFloat imageViewHeight = self.bounds.size.height - labelHeight; 36 | self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, imageViewHeight)]; 37 | self.imageView.contentMode = UIViewContentModeScaleAspectFill; 38 | self.imageView.layer.masksToBounds = true; 39 | [self addSubview:self.imageView]; 40 | 41 | self.textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, imageViewHeight, self.bounds.size.width, labelHeight)]; 42 | self.textLabel.textColor = [UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1]; 43 | self.textLabel.font = [UIFont systemFontOfSize:22]; 44 | self.textLabel.textAlignment = NSTextAlignmentCenter; 45 | self.textLabel.adjustsFontSizeToFitWidth = true; 46 | [self addSubview:self.textLabel]; 47 | } 48 | 49 | - (void)setModel:(XLCardModel *)model { 50 | self.imageView.image = [UIImage imageNamed:model.imageName]; 51 | self.textLabel.text = model.title; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CardModel.h 3 | // CardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/6. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XLCardModel : NSObject 12 | 13 | @property (nonatomic, copy) NSString *imageName; 14 | 15 | @property (nonatomic, copy) NSString *title; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CardModel.m 3 | // CardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/6. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import "XLCardModel.h" 10 | 11 | @implementation XLCardModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardSwitch.h: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitch.h 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/20. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "XLCardModel.h" 11 | 12 | @protocol XLCardSwitchDelegate 13 | 14 | @optional 15 | 16 | /** 17 | 点击卡片代理方法 18 | */ 19 | -(void)cardSwitchDidClickAtIndex:(NSInteger)index; 20 | 21 | /** 22 | 滚动卡片代理方法 23 | */ 24 | -(void)cardSwitchDidScrollToIndex:(NSInteger)index; 25 | 26 | @end 27 | 28 | @interface XLCardSwitch : UIView 29 | /** 30 | 当前选中位置 31 | */ 32 | @property (nonatomic, assign, readwrite) NSInteger selectedIndex; 33 | /** 34 | 设置数据源 35 | */ 36 | @property (nonatomic, strong) NSArray *models; 37 | /** 38 | 代理 39 | */ 40 | @property (nonatomic, weak) iddelegate; 41 | 42 | /** 43 | 是否分页,默认为true 44 | */ 45 | @property (nonatomic, assign) BOOL pagingEnabled; 46 | 47 | /** 48 | 手动滚动到某个卡片位置 49 | */ 50 | - (void)switchToIndex:(NSInteger)index animated:(BOOL)animated; 51 | 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardSwitch.m: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitch.m 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/20. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import "XLCardSwitch.h" 10 | #import "XLCardSwitchFlowLayout.h" 11 | #import "XLCardCell.h" 12 | 13 | @interface XLCardSwitch () 14 | 15 | @property (nonatomic, strong) UICollectionView *collectionView; 16 | 17 | @property (nonatomic, assign) CGFloat dragStartX; 18 | 19 | @property (nonatomic, assign) CGFloat dragEndX; 20 | 21 | @property (nonatomic, assign) CGFloat dragAtIndex; 22 | 23 | @end 24 | 25 | @implementation XLCardSwitch 26 | 27 | - (instancetype)init { 28 | if (self = [super init]) { 29 | [self buildUI]; 30 | } 31 | return self; 32 | } 33 | 34 | - (instancetype)initWithFrame:(CGRect)frame { 35 | if (self = [super initWithFrame:frame]) { 36 | [self buildUI]; 37 | } 38 | return self; 39 | } 40 | 41 | - (void)buildUI { 42 | [self addCollectionView]; 43 | } 44 | 45 | - (void)addCollectionView { 46 | //避免UINavigation对UIScrollView产生的偏移问题 47 | [self addSubview:[UIView new]]; 48 | XLCardSwitchFlowLayout *flowLayout = [[XLCardSwitchFlowLayout alloc] init]; 49 | __weak typeof(self)weakSelf = self; 50 | flowLayout.centerBlock = ^(NSIndexPath *indexPath) { 51 | [weakSelf updateSelectedIndex:indexPath]; 52 | }; 53 | self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout]; 54 | self.collectionView.showsHorizontalScrollIndicator = false; 55 | self.collectionView.backgroundColor = [UIColor clearColor]; 56 | [self.collectionView registerClass:[XLCardCell class] forCellWithReuseIdentifier:@"XLCardCell"]; 57 | self.collectionView.userInteractionEnabled = true; 58 | self.collectionView.delegate = self; 59 | self.collectionView.dataSource = self; 60 | [self addSubview:self.collectionView]; 61 | } 62 | 63 | - (void)layoutSubviews { 64 | [super layoutSubviews]; 65 | self.collectionView.frame = self.bounds; 66 | } 67 | 68 | - (void)updateSelectedIndex:(NSIndexPath *)indexPath { 69 | if (indexPath.row != _selectedIndex) { 70 | _selectedIndex = indexPath.row; 71 | [self performScrollDelegateMethod]; 72 | } 73 | } 74 | 75 | #pragma mark - 76 | #pragma mark Setter 77 | - (void)setModels:(NSArray *)models { 78 | _models = models; 79 | [self.collectionView reloadData]; 80 | } 81 | 82 | #pragma mark - 83 | #pragma mark CollectionDelegate 84 | //配置cell居中 85 | - (void)fixCellToCenter { 86 | if (_selectedIndex != [self dragAtIndex]) { 87 | [self scrollToCenterAnimated:true]; 88 | return; 89 | } 90 | //最小滚动距离 91 | float dragMiniDistance = self.bounds.size.width/20.0f; 92 | if (self.dragStartX - self.dragEndX >= dragMiniDistance) { 93 | _selectedIndex -= 1;//向右 94 | }else if(self.dragEndX - self.dragStartX >= dragMiniDistance){ 95 | _selectedIndex += 1;//向左 96 | } 97 | NSInteger maxIndex = [self.collectionView numberOfItemsInSection:0] - 1; 98 | _selectedIndex = _selectedIndex <= 0 ? 0 : _selectedIndex; 99 | _selectedIndex = _selectedIndex >= maxIndex ? maxIndex : _selectedIndex; 100 | [self scrollToCenterAnimated:true]; 101 | } 102 | 103 | //滚动到中间 104 | - (void)scrollToCenterAnimated:(BOOL)animated { 105 | [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:_selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES]; 106 | } 107 | 108 | //手指拖动开始 109 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 110 | if (!_pagingEnabled) {return;} 111 | self.dragStartX = scrollView.contentOffset.x; 112 | self.dragAtIndex = _selectedIndex; 113 | } 114 | 115 | //手指拖动停止 116 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 117 | if (!_pagingEnabled) {return;} 118 | self.dragEndX = scrollView.contentOffset.x; 119 | dispatch_async(dispatch_get_main_queue(), ^{ 120 | [self fixCellToCenter]; 121 | }); 122 | } 123 | 124 | //点击方法 125 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 126 | _selectedIndex = indexPath.row; 127 | [self scrollToCenterAnimated:YES]; 128 | [self performClickDelegateMethod]; 129 | } 130 | 131 | #pragma mark - 132 | #pragma mark CollectionDataSource 133 | 134 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 135 | return self.models.count; 136 | } 137 | 138 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 139 | return 1; 140 | } 141 | 142 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 143 | static NSString* cellId = @"XLCardCell"; 144 | XLCardCell* card = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; 145 | card.model = self.models[indexPath.row]; 146 | return card; 147 | } 148 | 149 | #pragma mark - 150 | #pragma mark 功能方法 151 | - (void)setSelectedIndex:(NSInteger)selectedIndex { 152 | _selectedIndex = selectedIndex; 153 | [self switchToIndex:selectedIndex animated:false]; 154 | } 155 | 156 | - (void)switchToIndex:(NSInteger)index animated:(BOOL)animated { 157 | _selectedIndex = index; 158 | [self scrollToCenterAnimated:animated]; 159 | } 160 | 161 | - (void)performClickDelegateMethod { 162 | if ([_delegate respondsToSelector:@selector(cardSwitchDidClickAtIndex:)]) { 163 | [_delegate cardSwitchDidClickAtIndex:_selectedIndex]; 164 | } 165 | } 166 | 167 | - (void)performScrollDelegateMethod { 168 | if ([_delegate respondsToSelector:@selector(cardSwitchDidScrollToIndex:)]) { 169 | [_delegate cardSwitchDidScrollToIndex:_selectedIndex]; 170 | } 171 | } 172 | 173 | 174 | @end 175 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardSwitchFlowLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitchFlowLayout.h 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/20. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^XLCenterIndexPathBlock)(NSIndexPath *indexPath); 12 | 13 | @interface XLCardSwitchFlowLayout : UICollectionViewFlowLayout 14 | 15 | @property (nonatomic , strong) XLCenterIndexPathBlock centerBlock; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitch/XLCardSwitchFlowLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitchFlowLayout.m 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/20. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import "XLCardSwitchFlowLayout.h" 10 | 11 | //居中卡片宽度与据屏幕宽度比例 12 | static float CardWidthScale = 0.7f; 13 | static float CardHeightScale = 0.8f; 14 | 15 | @implementation XLCardSwitchFlowLayout 16 | 17 | //初始化方法 18 | - (void)prepareLayout { 19 | [super prepareLayout]; 20 | self.scrollDirection = UICollectionViewScrollDirectionHorizontal; 21 | self.sectionInset = UIEdgeInsetsMake([self insetY], [self insetX], [self insetY], [self insetX]); 22 | self.itemSize = CGSizeMake([self itemWidth], [self itemHeight]); 23 | self.minimumLineSpacing = 5; 24 | } 25 | 26 | //设置缩放动画 27 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { 28 | //获取cell的布局 29 | NSArray *attributesArr = [super layoutAttributesForElementsInRect:rect]; 30 | //屏幕中线 31 | CGFloat centerX = self.collectionView.contentOffset.x + self.collectionView.bounds.size.width/2.0f; 32 | //最大移动距离,计算范围是移动出屏幕前的距离 33 | CGFloat maxApart = (self.collectionView.bounds.size.width + [self itemWidth])/2.0f; 34 | //刷新cell缩放 35 | for (UICollectionViewLayoutAttributes *attributes in attributesArr) { 36 | //获取cell中心和屏幕中心的距离 37 | CGFloat apart = fabs(attributes.center.x - centerX); 38 | //移动进度 -1~0~1 39 | CGFloat progress = apart/maxApart; 40 | //在屏幕外的cell不处理 41 | if (fabs(progress) > 1) {continue;} 42 | //根据余弦函数,弧度在 -π/4 到 π/4,即 scale在 √2/2~1~√2/2 间变化 43 | CGFloat scale = fabs(cos(progress * M_PI/4)); 44 | //缩放大小 45 | attributes.transform = CGAffineTransformMakeScale(scale, scale); 46 | //更新中间位 47 | if (apart <= [self itemWidth]/2.0f) { 48 | self.centerBlock(attributes.indexPath); 49 | } 50 | } 51 | return attributesArr; 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark 配置方法 56 | //卡片宽度 57 | - (CGFloat)itemWidth { 58 | return self.collectionView.bounds.size.width * CardWidthScale; 59 | } 60 | 61 | - (CGFloat)itemHeight { 62 | return self.collectionView.bounds.size.height * CardHeightScale; 63 | } 64 | 65 | //设置左右缩进 66 | - (CGFloat)insetX { 67 | CGFloat insetX = (self.collectionView.bounds.size.width - [self itemWidth])/2.0f; 68 | return insetX; 69 | } 70 | 71 | - (CGFloat)insetY { 72 | CGFloat insetY = (self.collectionView.bounds.size.height - [self itemHeight])/2.0f; 73 | return insetY; 74 | } 75 | 76 | //是否实时刷新布局 77 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 78 | return true; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 18760D0F1E1F4C9800007F02 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 18760D0E1E1F4C9800007F02 /* main.m */; }; 11 | 18760D121E1F4C9800007F02 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 18760D111E1F4C9800007F02 /* AppDelegate.m */; }; 12 | 18760D1A1E1F4C9800007F02 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 18760D191E1F4C9800007F02 /* Assets.xcassets */; }; 13 | 18760D1D1E1F4C9800007F02 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 18760D1B1E1F4C9800007F02 /* LaunchScreen.storyboard */; }; 14 | 18760D471E1F4D1300007F02 /* DataPropertyList.plist in Resources */ = {isa = PBXBuildFile; fileRef = 18760D461E1F4D1300007F02 /* DataPropertyList.plist */; }; 15 | 18760D4C1E1F4D2800007F02 /* XLCardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 18760D491E1F4D2800007F02 /* XLCardCell.m */; }; 16 | 18AEF9581E32090E00D8FD57 /* XLCardSwitchFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 18AEF9571E32090E00D8FD57 /* XLCardSwitchFlowLayout.m */; }; 17 | 18AEF95B1E32497000D8FD57 /* XLCardSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 18AEF95A1E32497000D8FD57 /* XLCardSwitch.m */; }; 18 | 18AEF9611E324BC600D8FD57 /* XLCardModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 18AEF9601E324BC600D8FD57 /* XLCardModel.m */; }; 19 | 5E36E4731EEBD9850016C8F8 /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E36E4721EEBD9850016C8F8 /* DemoViewController.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 18760D0A1E1F4C9800007F02 /* XLCardSwitchDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XLCardSwitchDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 18760D0E1E1F4C9800007F02 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 18760D101E1F4C9800007F02 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 26 | 18760D111E1F4C9800007F02 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 27 | 18760D191E1F4C9800007F02 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 18760D1C1E1F4C9800007F02 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 18760D1E1E1F4C9800007F02 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 18760D461E1F4D1300007F02 /* DataPropertyList.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = DataPropertyList.plist; sourceTree = ""; }; 31 | 18760D481E1F4D2800007F02 /* XLCardCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XLCardCell.h; sourceTree = ""; }; 32 | 18760D491E1F4D2800007F02 /* XLCardCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XLCardCell.m; sourceTree = ""; }; 33 | 18AEF9561E32090E00D8FD57 /* XLCardSwitchFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XLCardSwitchFlowLayout.h; sourceTree = ""; }; 34 | 18AEF9571E32090E00D8FD57 /* XLCardSwitchFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XLCardSwitchFlowLayout.m; sourceTree = ""; }; 35 | 18AEF9591E32497000D8FD57 /* XLCardSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XLCardSwitch.h; sourceTree = ""; }; 36 | 18AEF95A1E32497000D8FD57 /* XLCardSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XLCardSwitch.m; sourceTree = ""; }; 37 | 18AEF95F1E324BC600D8FD57 /* XLCardModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XLCardModel.h; sourceTree = ""; }; 38 | 18AEF9601E324BC600D8FD57 /* XLCardModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XLCardModel.m; sourceTree = ""; }; 39 | 5E36E4711EEBD9850016C8F8 /* DemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoViewController.h; sourceTree = ""; }; 40 | 5E36E4721EEBD9850016C8F8 /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 18760D071E1F4C9800007F02 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 18760D011E1F4C9800007F02 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 18760D271E1F4CE100007F02 /* XLCardSwitch */, 58 | 18760D251E1F4CB200007F02 /* Resource */, 59 | 18760D0C1E1F4C9800007F02 /* XLCardSwitchDemo */, 60 | 18760D0B1E1F4C9800007F02 /* Products */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | 18760D0B1E1F4C9800007F02 /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 18760D0A1E1F4C9800007F02 /* XLCardSwitchDemo.app */, 68 | ); 69 | name = Products; 70 | sourceTree = ""; 71 | }; 72 | 18760D0C1E1F4C9800007F02 /* XLCardSwitchDemo */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 5E36E4711EEBD9850016C8F8 /* DemoViewController.h */, 76 | 5E36E4721EEBD9850016C8F8 /* DemoViewController.m */, 77 | 18760D101E1F4C9800007F02 /* AppDelegate.h */, 78 | 18760D111E1F4C9800007F02 /* AppDelegate.m */, 79 | 18760D191E1F4C9800007F02 /* Assets.xcassets */, 80 | 18760D1B1E1F4C9800007F02 /* LaunchScreen.storyboard */, 81 | 18760D1E1E1F4C9800007F02 /* Info.plist */, 82 | 18760D0D1E1F4C9800007F02 /* Supporting Files */, 83 | ); 84 | path = XLCardSwitchDemo; 85 | sourceTree = ""; 86 | }; 87 | 18760D0D1E1F4C9800007F02 /* Supporting Files */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 18760D0E1E1F4C9800007F02 /* main.m */, 91 | ); 92 | name = "Supporting Files"; 93 | sourceTree = ""; 94 | }; 95 | 18760D251E1F4CB200007F02 /* Resource */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 18760D461E1F4D1300007F02 /* DataPropertyList.plist */, 99 | ); 100 | path = Resource; 101 | sourceTree = ""; 102 | }; 103 | 18760D271E1F4CE100007F02 /* XLCardSwitch */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 18AEF9591E32497000D8FD57 /* XLCardSwitch.h */, 107 | 18AEF95A1E32497000D8FD57 /* XLCardSwitch.m */, 108 | 18AEF9561E32090E00D8FD57 /* XLCardSwitchFlowLayout.h */, 109 | 18AEF9571E32090E00D8FD57 /* XLCardSwitchFlowLayout.m */, 110 | 18760D481E1F4D2800007F02 /* XLCardCell.h */, 111 | 18760D491E1F4D2800007F02 /* XLCardCell.m */, 112 | 18AEF95F1E324BC600D8FD57 /* XLCardModel.h */, 113 | 18AEF9601E324BC600D8FD57 /* XLCardModel.m */, 114 | ); 115 | path = XLCardSwitch; 116 | sourceTree = ""; 117 | }; 118 | /* End PBXGroup section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | 18760D091E1F4C9800007F02 /* XLCardSwitchDemo */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = 18760D211E1F4C9800007F02 /* Build configuration list for PBXNativeTarget "XLCardSwitchDemo" */; 124 | buildPhases = ( 125 | 18760D061E1F4C9800007F02 /* Sources */, 126 | 18760D071E1F4C9800007F02 /* Frameworks */, 127 | 18760D081E1F4C9800007F02 /* Resources */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = XLCardSwitchDemo; 134 | productName = XLCardSwitchDemo; 135 | productReference = 18760D0A1E1F4C9800007F02 /* XLCardSwitchDemo.app */; 136 | productType = "com.apple.product-type.application"; 137 | }; 138 | /* End PBXNativeTarget section */ 139 | 140 | /* Begin PBXProject section */ 141 | 18760D021E1F4C9800007F02 /* Project object */ = { 142 | isa = PBXProject; 143 | attributes = { 144 | LastUpgradeCheck = 1020; 145 | ORGANIZATIONNAME = Apple; 146 | TargetAttributes = { 147 | 18760D091E1F4C9800007F02 = { 148 | CreatedOnToolsVersion = 8.2; 149 | DevelopmentTeam = X496RVQDTB; 150 | ProvisioningStyle = Manual; 151 | }; 152 | }; 153 | }; 154 | buildConfigurationList = 18760D051E1F4C9800007F02 /* Build configuration list for PBXProject "XLCardSwitchDemo" */; 155 | compatibilityVersion = "Xcode 3.2"; 156 | developmentRegion = en; 157 | hasScannedForEncodings = 0; 158 | knownRegions = ( 159 | en, 160 | Base, 161 | ); 162 | mainGroup = 18760D011E1F4C9800007F02; 163 | productRefGroup = 18760D0B1E1F4C9800007F02 /* Products */; 164 | projectDirPath = ""; 165 | projectRoot = ""; 166 | targets = ( 167 | 18760D091E1F4C9800007F02 /* XLCardSwitchDemo */, 168 | ); 169 | }; 170 | /* End PBXProject section */ 171 | 172 | /* Begin PBXResourcesBuildPhase section */ 173 | 18760D081E1F4C9800007F02 /* Resources */ = { 174 | isa = PBXResourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | 18760D1D1E1F4C9800007F02 /* LaunchScreen.storyboard in Resources */, 178 | 18760D471E1F4D1300007F02 /* DataPropertyList.plist in Resources */, 179 | 18760D1A1E1F4C9800007F02 /* Assets.xcassets in Resources */, 180 | ); 181 | runOnlyForDeploymentPostprocessing = 0; 182 | }; 183 | /* End PBXResourcesBuildPhase section */ 184 | 185 | /* Begin PBXSourcesBuildPhase section */ 186 | 18760D061E1F4C9800007F02 /* Sources */ = { 187 | isa = PBXSourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | 18760D4C1E1F4D2800007F02 /* XLCardCell.m in Sources */, 191 | 18AEF9611E324BC600D8FD57 /* XLCardModel.m in Sources */, 192 | 18AEF9581E32090E00D8FD57 /* XLCardSwitchFlowLayout.m in Sources */, 193 | 5E36E4731EEBD9850016C8F8 /* DemoViewController.m in Sources */, 194 | 18760D121E1F4C9800007F02 /* AppDelegate.m in Sources */, 195 | 18760D0F1E1F4C9800007F02 /* main.m in Sources */, 196 | 18AEF95B1E32497000D8FD57 /* XLCardSwitch.m in Sources */, 197 | ); 198 | runOnlyForDeploymentPostprocessing = 0; 199 | }; 200 | /* End PBXSourcesBuildPhase section */ 201 | 202 | /* Begin PBXVariantGroup section */ 203 | 18760D1B1E1F4C9800007F02 /* LaunchScreen.storyboard */ = { 204 | isa = PBXVariantGroup; 205 | children = ( 206 | 18760D1C1E1F4C9800007F02 /* Base */, 207 | ); 208 | name = LaunchScreen.storyboard; 209 | sourceTree = ""; 210 | }; 211 | /* End PBXVariantGroup section */ 212 | 213 | /* Begin XCBuildConfiguration section */ 214 | 18760D1F1E1F4C9800007F02 /* Debug */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 219 | CLANG_ANALYZER_NONNULL = YES; 220 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 221 | CLANG_CXX_LIBRARY = "libc++"; 222 | CLANG_ENABLE_MODULES = YES; 223 | CLANG_ENABLE_OBJC_ARC = YES; 224 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 225 | CLANG_WARN_BOOL_CONVERSION = YES; 226 | CLANG_WARN_COMMA = YES; 227 | CLANG_WARN_CONSTANT_CONVERSION = YES; 228 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 230 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 231 | CLANG_WARN_EMPTY_BODY = YES; 232 | CLANG_WARN_ENUM_CONVERSION = YES; 233 | CLANG_WARN_INFINITE_RECURSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 236 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 237 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | CODE_SIGN_IDENTITY = "iPhone Developer: xianliang meng (79SX5888C3)"; 245 | COPY_PHASE_STRIP = NO; 246 | DEBUG_INFORMATION_FORMAT = dwarf; 247 | DEVELOPMENT_TEAM = X496RVQDTB; 248 | ENABLE_STRICT_OBJC_MSGSEND = YES; 249 | ENABLE_TESTABILITY = YES; 250 | GCC_C_LANGUAGE_STANDARD = gnu99; 251 | GCC_DYNAMIC_NO_PIC = NO; 252 | GCC_NO_COMMON_BLOCKS = YES; 253 | GCC_OPTIMIZATION_LEVEL = 0; 254 | GCC_PREPROCESSOR_DEFINITIONS = ( 255 | "DEBUG=1", 256 | "$(inherited)", 257 | ); 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 265 | MTL_ENABLE_DEBUG_INFO = YES; 266 | ONLY_ACTIVE_ARCH = YES; 267 | PROVISIONING_PROFILE = "63d0bee2-4f74-4b71-a719-620d70b5a076"; 268 | SDKROOT = iphoneos; 269 | }; 270 | name = Debug; 271 | }; 272 | 18760D201E1F4C9800007F02 /* Release */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ALWAYS_SEARCH_USER_PATHS = NO; 276 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 277 | CLANG_ANALYZER_NONNULL = YES; 278 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 279 | CLANG_CXX_LIBRARY = "libc++"; 280 | CLANG_ENABLE_MODULES = YES; 281 | CLANG_ENABLE_OBJC_ARC = YES; 282 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 283 | CLANG_WARN_BOOL_CONVERSION = YES; 284 | CLANG_WARN_COMMA = YES; 285 | CLANG_WARN_CONSTANT_CONVERSION = YES; 286 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 287 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 288 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 289 | CLANG_WARN_EMPTY_BODY = YES; 290 | CLANG_WARN_ENUM_CONVERSION = YES; 291 | CLANG_WARN_INFINITE_RECURSION = YES; 292 | CLANG_WARN_INT_CONVERSION = YES; 293 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 294 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 295 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 297 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 298 | CLANG_WARN_STRICT_PROTOTYPES = YES; 299 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 300 | CLANG_WARN_UNREACHABLE_CODE = YES; 301 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 302 | CODE_SIGN_IDENTITY = "iPhone Developer: xianliang meng (79SX5888C3)"; 303 | COPY_PHASE_STRIP = NO; 304 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 305 | DEVELOPMENT_TEAM = X496RVQDTB; 306 | ENABLE_NS_ASSERTIONS = NO; 307 | ENABLE_STRICT_OBJC_MSGSEND = YES; 308 | GCC_C_LANGUAGE_STANDARD = gnu99; 309 | GCC_NO_COMMON_BLOCKS = YES; 310 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 311 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 312 | GCC_WARN_UNDECLARED_SELECTOR = YES; 313 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 314 | GCC_WARN_UNUSED_FUNCTION = YES; 315 | GCC_WARN_UNUSED_VARIABLE = YES; 316 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 317 | MTL_ENABLE_DEBUG_INFO = NO; 318 | PROVISIONING_PROFILE = "63d0bee2-4f74-4b71-a719-620d70b5a076"; 319 | SDKROOT = iphoneos; 320 | VALIDATE_PRODUCT = YES; 321 | }; 322 | name = Release; 323 | }; 324 | 18760D221E1F4C9800007F02 /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 328 | CODE_SIGN_IDENTITY = "iPhone Developer: xianliang meng (79SX5888C3)"; 329 | CODE_SIGN_STYLE = Manual; 330 | DEVELOPMENT_TEAM = X496RVQDTB; 331 | INFOPLIST_FILE = XLCardSwitchDemo/Info.plist; 332 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 333 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 334 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchDemo; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | PROVISIONING_PROFILE = "63d0bee2-4f74-4b71-a719-620d70b5a076"; 337 | PROVISIONING_PROFILE_SPECIFIER = mxlDev; 338 | }; 339 | name = Debug; 340 | }; 341 | 18760D231E1F4C9800007F02 /* Release */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 345 | CODE_SIGN_IDENTITY = "iPhone Developer: xianliang meng (79SX5888C3)"; 346 | CODE_SIGN_STYLE = Manual; 347 | DEVELOPMENT_TEAM = X496RVQDTB; 348 | INFOPLIST_FILE = XLCardSwitchDemo/Info.plist; 349 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 350 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 351 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchDemo; 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | PROVISIONING_PROFILE = "63d0bee2-4f74-4b71-a719-620d70b5a076"; 354 | PROVISIONING_PROFILE_SPECIFIER = mxlDev; 355 | }; 356 | name = Release; 357 | }; 358 | /* End XCBuildConfiguration section */ 359 | 360 | /* Begin XCConfigurationList section */ 361 | 18760D051E1F4C9800007F02 /* Build configuration list for PBXProject "XLCardSwitchDemo" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | 18760D1F1E1F4C9800007F02 /* Debug */, 365 | 18760D201E1F4C9800007F02 /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | 18760D211E1F4C9800007F02 /* Build configuration list for PBXNativeTarget "XLCardSwitchDemo" */ = { 371 | isa = XCConfigurationList; 372 | buildConfigurations = ( 373 | 18760D221E1F4C9800007F02 /* Debug */, 374 | 18760D231E1F4C9800007F02 /* Release */, 375 | ); 376 | defaultConfigurationIsVisible = 0; 377 | defaultConfigurationName = Release; 378 | }; 379 | /* End XCConfigurationList section */ 380 | }; 381 | rootObject = 18760D021E1F4C9800007F02 /* Project object */; 382 | } 383 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/Apple.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/Apple.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/MengXianLiang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/MengXianLiang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/mxl.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/mxl.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/Apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/Apple.xcuserdatad/xcschemes/XLCardSwitchDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/Apple.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | XLCardSwitchDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 18760D091E1F4C9800007F02 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/MengXianLiang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/MengXianLiang.xcuserdatad/xcschemes/XLCardSwitchDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/MengXianLiang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | XLCardSwitchDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 18760D091E1F4C9800007F02 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo.xcodeproj/xcuserdata/mxl.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | XLCardSwitchDemo.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/6. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/6. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "DemoViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 21 | [self.window makeKeyAndVisible]; 22 | 23 | DemoViewController *vc = [[DemoViewController alloc] init]; 24 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; 25 | nav.navigationBar.translucent = false; 26 | self.window.rootViewController = nav; 27 | return YES; 28 | } 29 | 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application { 32 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 33 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 34 | } 35 | 36 | 37 | - (void)applicationDidEnterBackground:(UIApplication *)application { 38 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 39 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 40 | } 41 | 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application { 44 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 45 | } 46 | 47 | 48 | - (void)applicationDidBecomeActive:(UIApplication *)application { 49 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 50 | } 51 | 52 | 53 | - (void)applicationWillTerminate:(UIApplication *)application { 54 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/1.imageset/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/1.imageset/1.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/10.imageset/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/10.imageset/10.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/10.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "10.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/11.imageset/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/11.imageset/11.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/11.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "11.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/12.imageset/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/12.imageset/12.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/12.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "12.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/13.imageset/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/13.imageset/13.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/13.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "13.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/2.imageset/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/2.imageset/2.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "2.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/3.imageset/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/3.imageset/3.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "3.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/4.imageset/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/4.imageset/4.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "4.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/5.imageset/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/5.imageset/5.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/5.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "5.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/6.imageset/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/6.imageset/6.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/6.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "6.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/7.imageset/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/7.imageset/7.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/7.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "7.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/8.imageset/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/8.imageset/8.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/8.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "8.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/9.imageset/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/9.imageset/9.png -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/9.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "9.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Assets.xcassets/TestImages/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/DemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoViewController.h 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/20. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DemoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/DemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoViewController.m 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/20. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import "DemoViewController.h" 10 | #import "XLCardSwitch.h" 11 | 12 | @interface DemoViewController () 13 | 14 | @property (nonatomic, strong) XLCardSwitch *cardSwitch; 15 | 16 | @property (nonatomic, strong) UIImageView *imageView; 17 | 18 | @property (nonatomic, strong) NSMutableArray *models; 19 | 20 | 21 | @end 22 | 23 | @implementation DemoViewController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | 28 | self.title = @"XLCardSwitch"; 29 | self.view.backgroundColor = [UIColor whiteColor]; 30 | 31 | [self configNavigationBar]; 32 | 33 | [self addImageView]; 34 | 35 | [self addCardSwitch]; 36 | 37 | [self buildData]; 38 | } 39 | 40 | - (void)viewDidLayoutSubviews { 41 | [super viewDidLayoutSubviews]; 42 | self.imageView.frame = self.view.bounds; 43 | self.cardSwitch.frame = self.view.bounds; 44 | } 45 | 46 | - (void)configNavigationBar { 47 | 48 | self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Previous" style:UIBarButtonItemStylePlain target:self action:@selector(switchPrevious)]; 49 | 50 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(switchNext)]; 51 | 52 | UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"正常滚动",@"自动居中"]]; 53 | seg.selectedSegmentIndex = 0; 54 | [seg addTarget:self action:@selector(segMethod:) forControlEvents:UIControlEventValueChanged]; 55 | self.navigationItem.titleView = seg; 56 | } 57 | 58 | - (void)addImageView { 59 | self.imageView = [[UIImageView alloc] init]; 60 | [self.view addSubview:self.imageView]; 61 | 62 | //毛玻璃效果 63 | UIBlurEffect* effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 64 | UIVisualEffectView* effectView = [[UIVisualEffectView alloc] initWithEffect:effect]; 65 | effectView.frame = self.view.bounds; 66 | [self.imageView addSubview:effectView]; 67 | } 68 | 69 | - (void)addCardSwitch { 70 | //初始化 71 | self.cardSwitch = [[XLCardSwitch alloc] initWithFrame:self.view.bounds]; 72 | //设置代理方法 73 | self.cardSwitch.delegate = self; 74 | //分页切换 75 | self.cardSwitch.pagingEnabled = false; 76 | [self.view addSubview:self.cardSwitch]; 77 | } 78 | 79 | - (void)buildData { 80 | //初始化数据源 81 | NSString *filePath = [[NSBundle mainBundle] pathForResource:@"DataPropertyList" ofType:@"plist"]; 82 | NSArray *arr = [NSArray arrayWithContentsOfFile:filePath]; 83 | self.models = [NSMutableArray new]; 84 | for (NSDictionary *dic in arr) { 85 | XLCardModel *model = [[XLCardModel alloc] init]; 86 | [model setValuesForKeysWithDictionary:dic]; 87 | [self.models addObject:model]; 88 | } 89 | 90 | //设置卡片数据源 91 | self.cardSwitch.models = self.models; 92 | 93 | //更新背景图 94 | [self configImageViewOfIndex:self.cardSwitch.selectedIndex]; 95 | } 96 | 97 | //开关分页效果 98 | - (void)segMethod:(UISegmentedControl *)seg { 99 | switch (seg.selectedSegmentIndex) { 100 | case 0: 101 | self.cardSwitch.pagingEnabled = false; 102 | break; 103 | case 1: 104 | self.cardSwitch.pagingEnabled = true; 105 | break; 106 | default: 107 | break; 108 | } 109 | } 110 | 111 | #pragma mark - 112 | #pragma mark CardSwitchDelegate 113 | - (void)cardSwitchDidClickAtIndex:(NSInteger)index { 114 | NSLog(@"点击了:%zd",index); 115 | [self configImageViewOfIndex:index]; 116 | } 117 | 118 | - (void)cardSwitchDidScrollToIndex:(NSInteger)index { 119 | NSLog(@"滚动到了击了:%zd",index); 120 | [self configImageViewOfIndex:index]; 121 | } 122 | 123 | #pragma mark - 124 | #pragma mark 更新imageView 125 | - (void)configImageViewOfIndex:(NSInteger)index { 126 | //更新背景图 127 | XLCardModel *model = self.models[index]; 128 | self.imageView.image = [UIImage imageNamed:model.imageName]; 129 | } 130 | 131 | #pragma mark - 132 | #pragma mark 手动切换方法 133 | - (void)switchPrevious { 134 | NSInteger index = self.cardSwitch.selectedIndex - 1; 135 | index = index < 0 ? 0 : index; 136 | [self.cardSwitch switchToIndex:index animated:true]; 137 | } 138 | 139 | - (void)switchNext { 140 | NSInteger index = self.cardSwitch.selectedIndex + 1; 141 | index = index > self.models.count - 1 ? self.models.count - 1 : index; 142 | [self.cardSwitch switchToIndex:index animated:true]; 143 | } 144 | 145 | 146 | - (void)didReceiveMemoryWarning { 147 | [super didReceiveMemoryWarning]; 148 | } 149 | 150 | @end 151 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /XLCardSwitchDemo/XLCardSwitchDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // XLCardSwitchDemo 4 | // 5 | // Created by Apple on 2017/1/6. 6 | // Copyright © 2017年 Apple. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitch/XLCardSwitch.swift: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitch.swift 3 | // XLCardSwitchExample 4 | // 5 | // Created by MengXianLiang on 2019/8/27. 6 | // Copyright © 2019 mxl. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// 滚动切换回调方法 12 | typealias XLCardScollIndexChangeBlock = (_ index: Int) -> Void 13 | 14 | /// 布局类 15 | class XLCardSwitchFlowLayout: UICollectionViewFlowLayout { 16 | /// 卡片和父视图宽度比例 17 | let cardWidthScale: CGFloat = 0.7 18 | /// 卡片和父视图高度比例 19 | let cardHeightScale: CGFloat = 0.8 20 | /// 滚动到中间的调方法 21 | var indexChangeBlock: XLCardScollIndexChangeBlock? 22 | 23 | override func prepare() { 24 | super.prepare() 25 | scrollDirection = UICollectionView.ScrollDirection.horizontal 26 | sectionInset = UIEdgeInsets(top: insetY(), left: insetX(), bottom: insetY(), right: insetX()) 27 | itemSize = CGSize(width: itemWidth(), height: itemHeight()) 28 | minimumLineSpacing = 5 29 | } 30 | 31 | override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 32 | //获取cell的布局 33 | guard let originalAttributesArr = super.layoutAttributesForElements(in: rect) else { 34 | return super.layoutAttributesForElements(in: rect) 35 | } 36 | 37 | guard let collectionView = self.collectionView else { return originalAttributesArr } 38 | 39 | //复制布局,以下操作,在复制布局中处理 40 | var attributesArr = [UICollectionViewLayoutAttributes]() 41 | for attr: UICollectionViewLayoutAttributes in originalAttributesArr { 42 | attributesArr.append(attr.copy() as! UICollectionViewLayoutAttributes) 43 | } 44 | 45 | //屏幕中线 46 | let centerX: CGFloat = collectionView.contentOffset.x + collectionView.bounds.size.width/2.0 47 | 48 | //最大移动距离,计算范围是移动出屏幕前的距离 49 | let maxApart: CGFloat = (collectionView.bounds.size.width + itemWidth())/2.0 50 | 51 | //刷新cell缩放 52 | for attributes: UICollectionViewLayoutAttributes in attributesArr { 53 | //获取cell中心和屏幕中心的距离 54 | let apart: CGFloat = abs(attributes.center.x - centerX) 55 | //移动进度 -1~0~1 56 | let progress: CGFloat = apart/maxApart 57 | //在屏幕外的cell不处理 58 | if (abs(progress) > 1) {continue} 59 | //根据余弦函数,弧度在 -π/4 到 π/4,即 scale在 √2/2~1~√2/2 间变化 60 | let scale: CGFloat = abs(cos(progress * CGFloat(Double.pi/4))) 61 | //缩放大小 62 | attributes.transform = CGAffineTransform.init(scaleX: scale, y: scale) 63 | //更新中间位 64 | if (apart <= itemWidth()/2.0) { 65 | indexChangeBlock?(attributes.indexPath.row) 66 | } 67 | } 68 | return attributesArr 69 | } 70 | 71 | /// MARK - 72 | /// MARK 配置方法 73 | /// 卡片宽度 74 | func itemWidth() -> CGFloat { 75 | return (collectionView?.bounds.size.width ?? 0) * cardWidthScale 76 | } 77 | 78 | /// 卡片高度 79 | func itemHeight() -> CGFloat { 80 | return (collectionView?.bounds.size.height ?? 0) * cardHeightScale 81 | } 82 | 83 | /// 设置左右缩进 84 | func insetX() -> CGFloat { 85 | let insetX = ((collectionView?.bounds.size.width ?? 0) - itemWidth())/2.0 86 | return insetX 87 | } 88 | 89 | /// 上下缩进 90 | func insetY() -> CGFloat { 91 | let insetY = ((collectionView?.bounds.size.height ?? 0) - itemHeight())/2.0 92 | return insetY 93 | } 94 | 95 | /// 是否实时刷新布局 96 | override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { 97 | super.shouldInvalidateLayout(forBoundsChange: newBounds) 98 | return true 99 | } 100 | } 101 | 102 | /// 代理 103 | @objc protocol XLCardSwitchDelegate: NSObjectProtocol { 104 | /// 滑动切换到新的位置回调 105 | @objc optional func cardSwitchDidScrollToIndex(index: Int) 106 | /// 手动点击了 107 | @objc optional func cardSwitchDidSelectedAtIndex(index: Int) 108 | } 109 | 110 | /// 数据源 111 | @objc protocol XLCardSwitchDataSource: NSObjectProtocol { 112 | /// 卡片的个数 113 | func cardSwitchNumberOfCard() -> (Int) 114 | /// 卡片cell 115 | func cardSwitchCellForItemAtIndex(index: Int) -> (UICollectionViewCell) 116 | } 117 | 118 | /// 展示类 119 | class XLCardSwitch: UIView ,UICollectionViewDelegate,UICollectionViewDataSource { 120 | /// 公有属性 121 | weak var delegate: XLCardSwitchDelegate? 122 | weak var dataSource: XLCardSwitchDataSource? 123 | var selectedIndex: Int = 0 124 | var pagingEnabled: Bool = false 125 | 126 | /// 私有属性 127 | private var dragStartX: CGFloat = 0 128 | private var dragEndX: CGFloat = 0 129 | private var dragAtIndex: Int = 0 130 | 131 | private let flowlayout = XLCardSwitchFlowLayout() 132 | 133 | private lazy var collectionView: UICollectionView = { 134 | let view = UICollectionView(frame: .zero, collectionViewLayout: flowlayout) 135 | view.delegate = self 136 | view.dataSource = self 137 | view.backgroundColor = UIColor.clear 138 | view.showsHorizontalScrollIndicator = false 139 | return view 140 | }() 141 | 142 | required init?(coder aDecoder: NSCoder) { 143 | super.init(coder: aDecoder) 144 | } 145 | 146 | override init(frame: CGRect) { 147 | super.init(frame: frame) 148 | buildUI() 149 | } 150 | 151 | func buildUI() { 152 | addSubview(collectionView) 153 | 154 | /// 添加回调方法 155 | flowlayout.indexChangeBlock = { (index) in 156 | if self.selectedIndex != index { 157 | self.selectedIndex = index 158 | self.delegateUpdateScrollIndex(index: index) 159 | } 160 | } 161 | } 162 | 163 | /// MARK:自动布局 164 | override func layoutSubviews() { 165 | super.layoutSubviews() 166 | collectionView.frame = bounds 167 | } 168 | 169 | /// MARK:- 170 | /// MARK:CollectionView方法 171 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 172 | return (dataSource?.cardSwitchNumberOfCard()) ?? 0 173 | } 174 | 175 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 176 | return (dataSource?.cardSwitchCellForItemAtIndex(index: indexPath.row))! 177 | } 178 | 179 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 180 | /// 执行代理方法 181 | selectedIndex = indexPath.row 182 | scrollToCenterAnimated(animated: true) 183 | delegateSelectedAtIndex(index: indexPath.row) 184 | } 185 | 186 | /// MARK:- 187 | /// MARK:ScrollViewDelegate 188 | @objc func fixCellToCenter() { 189 | if selectedIndex != dragAtIndex { 190 | scrollToCenterAnimated(animated: true) 191 | return 192 | } 193 | //最小滚动距离 194 | let dragMiniDistance: CGFloat = bounds.size.width/20.0 195 | if dragStartX - dragEndX >= dragMiniDistance { 196 | selectedIndex -= 1//向右 197 | }else if dragEndX - dragStartX >= dragMiniDistance { 198 | selectedIndex += 1 //向左 199 | } 200 | 201 | let maxIndex: Int = (collectionView.numberOfItems(inSection: 0)) - 1 202 | selectedIndex = max(selectedIndex, 0) 203 | selectedIndex = min(selectedIndex, maxIndex) 204 | scrollToCenterAnimated(animated: true) 205 | } 206 | 207 | /// 滚动到中间 208 | func scrollToCenterAnimated(animated: Bool) { 209 | collectionView.scrollToItem(at: IndexPath.init(row:selectedIndex, section: 0), at: UICollectionView.ScrollPosition.centeredHorizontally, animated: true) 210 | } 211 | 212 | /// 手指拖动开始 213 | func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { 214 | if (!pagingEnabled) { return } 215 | dragStartX = scrollView.contentOffset.x 216 | dragAtIndex = selectedIndex 217 | } 218 | 219 | /// 手指拖动停止 220 | func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { 221 | if (!pagingEnabled) { return } 222 | dragEndX = scrollView.contentOffset.x 223 | //在主线程执行居中方法 224 | DispatchQueue.main.async { 225 | self.fixCellToCenter() 226 | } 227 | } 228 | 229 | /// MARK:- 230 | /// MARK:执行代理方法 231 | /// 回调滚动方法 232 | func delegateUpdateScrollIndex(index: Int) { 233 | guard let delegate = delegate else { return } 234 | if (delegate.responds(to: #selector(delegate.cardSwitchDidScrollToIndex(index:)))) { 235 | delegate.cardSwitchDidScrollToIndex?(index: index) 236 | } 237 | } 238 | 239 | /// 回调点击方法 240 | func delegateSelectedAtIndex(index: Int) { 241 | guard let delegate = delegate else { return } 242 | if (delegate.responds(to: #selector(delegate.cardSwitchDidSelectedAtIndex(index:)))) { 243 | delegate.cardSwitchDidSelectedAtIndex?(index: index) 244 | } 245 | } 246 | 247 | /// MARK:- 248 | /// MARK:切换位置方法 249 | func switchToIndex(index: Int) { 250 | DispatchQueue.main.async { 251 | self.selectedIndex = index 252 | self.scrollToCenterAnimated(animated: true) 253 | } 254 | } 255 | 256 | /// 向前切换 257 | func switchPrevious() { 258 | guard let index = currentIndex() else { return } 259 | var targetIndex = index - 1 260 | targetIndex = max(0, targetIndex) 261 | switchToIndex(index: targetIndex) 262 | } 263 | 264 | /// 向后切换 265 | func switchNext() { 266 | guard let index = currentIndex() else { return } 267 | var targetIndex = index + 1 268 | let maxIndex = (dataSource?.cardSwitchNumberOfCard() ?? 0) - 1 269 | targetIndex = min(maxIndex, targetIndex) 270 | 271 | switchToIndex(index: targetIndex) 272 | } 273 | 274 | func currentIndex() -> Int? { 275 | let x = collectionView.contentOffset.x + collectionView.bounds.width/2 276 | return collectionView.indexPathForItem(at: CGPoint(x: x, y: collectionView.bounds.height/2))?.item 277 | } 278 | 279 | /// MARK:- 280 | /// MARK:数据源相关方法 281 | open func register(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String) { 282 | collectionView.register(cellClass, forCellWithReuseIdentifier: identifier) 283 | } 284 | 285 | open func dequeueReusableCell(withReuseIdentifier identifier: String, for index: Int) -> UICollectionViewCell { 286 | return collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: IndexPath(row: index, section: 0)) 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E4508C72315052E00FFE1E0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4508C62315052E00FFE1E0 /* AppDelegate.swift */; }; 11 | 5E4508C92315052E00FFE1E0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4508C82315052E00FFE1E0 /* ViewController.swift */; }; 12 | 5E4508CC2315052E00FFE1E0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5E4508CA2315052E00FFE1E0 /* Main.storyboard */; }; 13 | 5E4508CE2315053000FFE1E0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E4508CD2315053000FFE1E0 /* Assets.xcassets */; }; 14 | 5E4508D12315053000FFE1E0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5E4508CF2315053000FFE1E0 /* LaunchScreen.storyboard */; }; 15 | 5E4508DC2315053000FFE1E0 /* XLCardSwitchExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4508DB2315053000FFE1E0 /* XLCardSwitchExampleTests.swift */; }; 16 | 5E4508E72315053000FFE1E0 /* XLCardSwitchExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4508E62315053000FFE1E0 /* XLCardSwitchExampleUITests.swift */; }; 17 | 5E4508F6231509E400FFE1E0 /* XLCardSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4508F5231509E400FFE1E0 /* XLCardSwitch.swift */; }; 18 | 5E4509572316B36B00FFE1E0 /* CustomCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4509562316B36B00FFE1E0 /* CustomCollectionViewCell.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 5E4508D82315053000FFE1E0 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 5E4508BB2315052E00FFE1E0 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 5E4508C22315052E00FFE1E0; 27 | remoteInfo = XLCardSwitchExample; 28 | }; 29 | 5E4508E32315053000FFE1E0 /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 5E4508BB2315052E00FFE1E0 /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 5E4508C22315052E00FFE1E0; 34 | remoteInfo = XLCardSwitchExample; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 5E4508C32315052E00FFE1E0 /* XLCardSwitchExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XLCardSwitchExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 5E4508C62315052E00FFE1E0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 41 | 5E4508C82315052E00FFE1E0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 42 | 5E4508CB2315052E00FFE1E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 43 | 5E4508CD2315053000FFE1E0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 44 | 5E4508D02315053000FFE1E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 45 | 5E4508D22315053000FFE1E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | 5E4508D72315053000FFE1E0 /* XLCardSwitchExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XLCardSwitchExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | 5E4508DB2315053000FFE1E0 /* XLCardSwitchExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XLCardSwitchExampleTests.swift; sourceTree = ""; }; 48 | 5E4508DD2315053000FFE1E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | 5E4508E22315053000FFE1E0 /* XLCardSwitchExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XLCardSwitchExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 5E4508E62315053000FFE1E0 /* XLCardSwitchExampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XLCardSwitchExampleUITests.swift; sourceTree = ""; }; 51 | 5E4508E82315053000FFE1E0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 5E4508F5231509E400FFE1E0 /* XLCardSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XLCardSwitch.swift; sourceTree = ""; }; 53 | 5E4509562316B36B00FFE1E0 /* CustomCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCollectionViewCell.swift; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 5E4508C02315052E00FFE1E0 /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | ); 62 | runOnlyForDeploymentPostprocessing = 0; 63 | }; 64 | 5E4508D42315053000FFE1E0 /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | 5E4508DF2315053000FFE1E0 /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | 5E4508BA2315052E00FFE1E0 = { 82 | isa = PBXGroup; 83 | children = ( 84 | 5E4508F4231509D100FFE1E0 /* XLCardSwitch */, 85 | 5E4508C52315052E00FFE1E0 /* XLCardSwitchExample */, 86 | 5E4508DA2315053000FFE1E0 /* XLCardSwitchExampleTests */, 87 | 5E4508E52315053000FFE1E0 /* XLCardSwitchExampleUITests */, 88 | 5E4508C42315052E00FFE1E0 /* Products */, 89 | ); 90 | sourceTree = ""; 91 | }; 92 | 5E4508C42315052E00FFE1E0 /* Products */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 5E4508C32315052E00FFE1E0 /* XLCardSwitchExample.app */, 96 | 5E4508D72315053000FFE1E0 /* XLCardSwitchExampleTests.xctest */, 97 | 5E4508E22315053000FFE1E0 /* XLCardSwitchExampleUITests.xctest */, 98 | ); 99 | name = Products; 100 | sourceTree = ""; 101 | }; 102 | 5E4508C52315052E00FFE1E0 /* XLCardSwitchExample */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 5E4508C62315052E00FFE1E0 /* AppDelegate.swift */, 106 | 5E4508C82315052E00FFE1E0 /* ViewController.swift */, 107 | 5E4509562316B36B00FFE1E0 /* CustomCollectionViewCell.swift */, 108 | 5E4508CA2315052E00FFE1E0 /* Main.storyboard */, 109 | 5E4508CD2315053000FFE1E0 /* Assets.xcassets */, 110 | 5E4508CF2315053000FFE1E0 /* LaunchScreen.storyboard */, 111 | 5E4508D22315053000FFE1E0 /* Info.plist */, 112 | ); 113 | path = XLCardSwitchExample; 114 | sourceTree = ""; 115 | }; 116 | 5E4508DA2315053000FFE1E0 /* XLCardSwitchExampleTests */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 5E4508DB2315053000FFE1E0 /* XLCardSwitchExampleTests.swift */, 120 | 5E4508DD2315053000FFE1E0 /* Info.plist */, 121 | ); 122 | path = XLCardSwitchExampleTests; 123 | sourceTree = ""; 124 | }; 125 | 5E4508E52315053000FFE1E0 /* XLCardSwitchExampleUITests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 5E4508E62315053000FFE1E0 /* XLCardSwitchExampleUITests.swift */, 129 | 5E4508E82315053000FFE1E0 /* Info.plist */, 130 | ); 131 | path = XLCardSwitchExampleUITests; 132 | sourceTree = ""; 133 | }; 134 | 5E4508F4231509D100FFE1E0 /* XLCardSwitch */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 5E4508F5231509E400FFE1E0 /* XLCardSwitch.swift */, 138 | ); 139 | path = XLCardSwitch; 140 | sourceTree = ""; 141 | }; 142 | /* End PBXGroup section */ 143 | 144 | /* Begin PBXNativeTarget section */ 145 | 5E4508C22315052E00FFE1E0 /* XLCardSwitchExample */ = { 146 | isa = PBXNativeTarget; 147 | buildConfigurationList = 5E4508EB2315053000FFE1E0 /* Build configuration list for PBXNativeTarget "XLCardSwitchExample" */; 148 | buildPhases = ( 149 | 5E4508BF2315052E00FFE1E0 /* Sources */, 150 | 5E4508C02315052E00FFE1E0 /* Frameworks */, 151 | 5E4508C12315052E00FFE1E0 /* Resources */, 152 | ); 153 | buildRules = ( 154 | ); 155 | dependencies = ( 156 | ); 157 | name = XLCardSwitchExample; 158 | productName = XLCardSwitchExample; 159 | productReference = 5E4508C32315052E00FFE1E0 /* XLCardSwitchExample.app */; 160 | productType = "com.apple.product-type.application"; 161 | }; 162 | 5E4508D62315053000FFE1E0 /* XLCardSwitchExampleTests */ = { 163 | isa = PBXNativeTarget; 164 | buildConfigurationList = 5E4508EE2315053000FFE1E0 /* Build configuration list for PBXNativeTarget "XLCardSwitchExampleTests" */; 165 | buildPhases = ( 166 | 5E4508D32315053000FFE1E0 /* Sources */, 167 | 5E4508D42315053000FFE1E0 /* Frameworks */, 168 | 5E4508D52315053000FFE1E0 /* Resources */, 169 | ); 170 | buildRules = ( 171 | ); 172 | dependencies = ( 173 | 5E4508D92315053000FFE1E0 /* PBXTargetDependency */, 174 | ); 175 | name = XLCardSwitchExampleTests; 176 | productName = XLCardSwitchExampleTests; 177 | productReference = 5E4508D72315053000FFE1E0 /* XLCardSwitchExampleTests.xctest */; 178 | productType = "com.apple.product-type.bundle.unit-test"; 179 | }; 180 | 5E4508E12315053000FFE1E0 /* XLCardSwitchExampleUITests */ = { 181 | isa = PBXNativeTarget; 182 | buildConfigurationList = 5E4508F12315053000FFE1E0 /* Build configuration list for PBXNativeTarget "XLCardSwitchExampleUITests" */; 183 | buildPhases = ( 184 | 5E4508DE2315053000FFE1E0 /* Sources */, 185 | 5E4508DF2315053000FFE1E0 /* Frameworks */, 186 | 5E4508E02315053000FFE1E0 /* Resources */, 187 | ); 188 | buildRules = ( 189 | ); 190 | dependencies = ( 191 | 5E4508E42315053000FFE1E0 /* PBXTargetDependency */, 192 | ); 193 | name = XLCardSwitchExampleUITests; 194 | productName = XLCardSwitchExampleUITests; 195 | productReference = 5E4508E22315053000FFE1E0 /* XLCardSwitchExampleUITests.xctest */; 196 | productType = "com.apple.product-type.bundle.ui-testing"; 197 | }; 198 | /* End PBXNativeTarget section */ 199 | 200 | /* Begin PBXProject section */ 201 | 5E4508BB2315052E00FFE1E0 /* Project object */ = { 202 | isa = PBXProject; 203 | attributes = { 204 | LastSwiftUpdateCheck = 1020; 205 | LastUpgradeCheck = 1020; 206 | ORGANIZATIONNAME = mxl; 207 | TargetAttributes = { 208 | 5E4508C22315052E00FFE1E0 = { 209 | CreatedOnToolsVersion = 10.2; 210 | }; 211 | 5E4508D62315053000FFE1E0 = { 212 | CreatedOnToolsVersion = 10.2; 213 | TestTargetID = 5E4508C22315052E00FFE1E0; 214 | }; 215 | 5E4508E12315053000FFE1E0 = { 216 | CreatedOnToolsVersion = 10.2; 217 | TestTargetID = 5E4508C22315052E00FFE1E0; 218 | }; 219 | }; 220 | }; 221 | buildConfigurationList = 5E4508BE2315052E00FFE1E0 /* Build configuration list for PBXProject "XLCardSwitchExample" */; 222 | compatibilityVersion = "Xcode 9.3"; 223 | developmentRegion = en; 224 | hasScannedForEncodings = 0; 225 | knownRegions = ( 226 | en, 227 | Base, 228 | ); 229 | mainGroup = 5E4508BA2315052E00FFE1E0; 230 | productRefGroup = 5E4508C42315052E00FFE1E0 /* Products */; 231 | projectDirPath = ""; 232 | projectRoot = ""; 233 | targets = ( 234 | 5E4508C22315052E00FFE1E0 /* XLCardSwitchExample */, 235 | 5E4508D62315053000FFE1E0 /* XLCardSwitchExampleTests */, 236 | 5E4508E12315053000FFE1E0 /* XLCardSwitchExampleUITests */, 237 | ); 238 | }; 239 | /* End PBXProject section */ 240 | 241 | /* Begin PBXResourcesBuildPhase section */ 242 | 5E4508C12315052E00FFE1E0 /* Resources */ = { 243 | isa = PBXResourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | 5E4508D12315053000FFE1E0 /* LaunchScreen.storyboard in Resources */, 247 | 5E4508CE2315053000FFE1E0 /* Assets.xcassets in Resources */, 248 | 5E4508CC2315052E00FFE1E0 /* Main.storyboard in Resources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | 5E4508D52315053000FFE1E0 /* Resources */ = { 253 | isa = PBXResourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | 5E4508E02315053000FFE1E0 /* Resources */ = { 260 | isa = PBXResourcesBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | /* End PBXResourcesBuildPhase section */ 267 | 268 | /* Begin PBXSourcesBuildPhase section */ 269 | 5E4508BF2315052E00FFE1E0 /* Sources */ = { 270 | isa = PBXSourcesBuildPhase; 271 | buildActionMask = 2147483647; 272 | files = ( 273 | 5E4508F6231509E400FFE1E0 /* XLCardSwitch.swift in Sources */, 274 | 5E4508C92315052E00FFE1E0 /* ViewController.swift in Sources */, 275 | 5E4508C72315052E00FFE1E0 /* AppDelegate.swift in Sources */, 276 | 5E4509572316B36B00FFE1E0 /* CustomCollectionViewCell.swift in Sources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | 5E4508D32315053000FFE1E0 /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | 5E4508DC2315053000FFE1E0 /* XLCardSwitchExampleTests.swift in Sources */, 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | }; 288 | 5E4508DE2315053000FFE1E0 /* Sources */ = { 289 | isa = PBXSourcesBuildPhase; 290 | buildActionMask = 2147483647; 291 | files = ( 292 | 5E4508E72315053000FFE1E0 /* XLCardSwitchExampleUITests.swift in Sources */, 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | }; 296 | /* End PBXSourcesBuildPhase section */ 297 | 298 | /* Begin PBXTargetDependency section */ 299 | 5E4508D92315053000FFE1E0 /* PBXTargetDependency */ = { 300 | isa = PBXTargetDependency; 301 | target = 5E4508C22315052E00FFE1E0 /* XLCardSwitchExample */; 302 | targetProxy = 5E4508D82315053000FFE1E0 /* PBXContainerItemProxy */; 303 | }; 304 | 5E4508E42315053000FFE1E0 /* PBXTargetDependency */ = { 305 | isa = PBXTargetDependency; 306 | target = 5E4508C22315052E00FFE1E0 /* XLCardSwitchExample */; 307 | targetProxy = 5E4508E32315053000FFE1E0 /* PBXContainerItemProxy */; 308 | }; 309 | /* End PBXTargetDependency section */ 310 | 311 | /* Begin PBXVariantGroup section */ 312 | 5E4508CA2315052E00FFE1E0 /* Main.storyboard */ = { 313 | isa = PBXVariantGroup; 314 | children = ( 315 | 5E4508CB2315052E00FFE1E0 /* Base */, 316 | ); 317 | name = Main.storyboard; 318 | sourceTree = ""; 319 | }; 320 | 5E4508CF2315053000FFE1E0 /* LaunchScreen.storyboard */ = { 321 | isa = PBXVariantGroup; 322 | children = ( 323 | 5E4508D02315053000FFE1E0 /* Base */, 324 | ); 325 | name = LaunchScreen.storyboard; 326 | sourceTree = ""; 327 | }; 328 | /* End PBXVariantGroup section */ 329 | 330 | /* Begin XCBuildConfiguration section */ 331 | 5E4508E92315053000FFE1E0 /* Debug */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ALWAYS_SEARCH_USER_PATHS = NO; 335 | CLANG_ANALYZER_NONNULL = YES; 336 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 337 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 338 | CLANG_CXX_LIBRARY = "libc++"; 339 | CLANG_ENABLE_MODULES = YES; 340 | CLANG_ENABLE_OBJC_ARC = YES; 341 | CLANG_ENABLE_OBJC_WEAK = YES; 342 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 343 | CLANG_WARN_BOOL_CONVERSION = YES; 344 | CLANG_WARN_COMMA = YES; 345 | CLANG_WARN_CONSTANT_CONVERSION = YES; 346 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 347 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 348 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 349 | CLANG_WARN_EMPTY_BODY = YES; 350 | CLANG_WARN_ENUM_CONVERSION = YES; 351 | CLANG_WARN_INFINITE_RECURSION = YES; 352 | CLANG_WARN_INT_CONVERSION = YES; 353 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 354 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 355 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 356 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 357 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 358 | CLANG_WARN_STRICT_PROTOTYPES = YES; 359 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 360 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 361 | CLANG_WARN_UNREACHABLE_CODE = YES; 362 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 363 | CODE_SIGN_IDENTITY = "iPhone Developer"; 364 | COPY_PHASE_STRIP = NO; 365 | DEBUG_INFORMATION_FORMAT = dwarf; 366 | ENABLE_STRICT_OBJC_MSGSEND = YES; 367 | ENABLE_TESTABILITY = YES; 368 | GCC_C_LANGUAGE_STANDARD = gnu11; 369 | GCC_DYNAMIC_NO_PIC = NO; 370 | GCC_NO_COMMON_BLOCKS = YES; 371 | GCC_OPTIMIZATION_LEVEL = 0; 372 | GCC_PREPROCESSOR_DEFINITIONS = ( 373 | "DEBUG=1", 374 | "$(inherited)", 375 | ); 376 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 377 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 378 | GCC_WARN_UNDECLARED_SELECTOR = YES; 379 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 380 | GCC_WARN_UNUSED_FUNCTION = YES; 381 | GCC_WARN_UNUSED_VARIABLE = YES; 382 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 383 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 384 | MTL_FAST_MATH = YES; 385 | ONLY_ACTIVE_ARCH = YES; 386 | SDKROOT = iphoneos; 387 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 388 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 389 | }; 390 | name = Debug; 391 | }; 392 | 5E4508EA2315053000FFE1E0 /* Release */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | ALWAYS_SEARCH_USER_PATHS = NO; 396 | CLANG_ANALYZER_NONNULL = YES; 397 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 398 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 399 | CLANG_CXX_LIBRARY = "libc++"; 400 | CLANG_ENABLE_MODULES = YES; 401 | CLANG_ENABLE_OBJC_ARC = YES; 402 | CLANG_ENABLE_OBJC_WEAK = YES; 403 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 404 | CLANG_WARN_BOOL_CONVERSION = YES; 405 | CLANG_WARN_COMMA = YES; 406 | CLANG_WARN_CONSTANT_CONVERSION = YES; 407 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 408 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 409 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 410 | CLANG_WARN_EMPTY_BODY = YES; 411 | CLANG_WARN_ENUM_CONVERSION = YES; 412 | CLANG_WARN_INFINITE_RECURSION = YES; 413 | CLANG_WARN_INT_CONVERSION = YES; 414 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 415 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 416 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 417 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 418 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 419 | CLANG_WARN_STRICT_PROTOTYPES = YES; 420 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 421 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 422 | CLANG_WARN_UNREACHABLE_CODE = YES; 423 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 424 | CODE_SIGN_IDENTITY = "iPhone Developer"; 425 | COPY_PHASE_STRIP = NO; 426 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 427 | ENABLE_NS_ASSERTIONS = NO; 428 | ENABLE_STRICT_OBJC_MSGSEND = YES; 429 | GCC_C_LANGUAGE_STANDARD = gnu11; 430 | GCC_NO_COMMON_BLOCKS = YES; 431 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 432 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 433 | GCC_WARN_UNDECLARED_SELECTOR = YES; 434 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 435 | GCC_WARN_UNUSED_FUNCTION = YES; 436 | GCC_WARN_UNUSED_VARIABLE = YES; 437 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 438 | MTL_ENABLE_DEBUG_INFO = NO; 439 | MTL_FAST_MATH = YES; 440 | SDKROOT = iphoneos; 441 | SWIFT_COMPILATION_MODE = wholemodule; 442 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 443 | VALIDATE_PRODUCT = YES; 444 | }; 445 | name = Release; 446 | }; 447 | 5E4508EC2315053000FFE1E0 /* Debug */ = { 448 | isa = XCBuildConfiguration; 449 | buildSettings = { 450 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 451 | CODE_SIGN_STYLE = Automatic; 452 | DEVELOPMENT_TEAM = X496RVQDTB; 453 | INFOPLIST_FILE = XLCardSwitchExample/Info.plist; 454 | LD_RUNPATH_SEARCH_PATHS = ( 455 | "$(inherited)", 456 | "@executable_path/Frameworks", 457 | ); 458 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchExample; 459 | PRODUCT_NAME = "$(TARGET_NAME)"; 460 | SWIFT_VERSION = 5.0; 461 | TARGETED_DEVICE_FAMILY = "1,2"; 462 | }; 463 | name = Debug; 464 | }; 465 | 5E4508ED2315053000FFE1E0 /* Release */ = { 466 | isa = XCBuildConfiguration; 467 | buildSettings = { 468 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 469 | CODE_SIGN_STYLE = Automatic; 470 | DEVELOPMENT_TEAM = X496RVQDTB; 471 | INFOPLIST_FILE = XLCardSwitchExample/Info.plist; 472 | LD_RUNPATH_SEARCH_PATHS = ( 473 | "$(inherited)", 474 | "@executable_path/Frameworks", 475 | ); 476 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchExample; 477 | PRODUCT_NAME = "$(TARGET_NAME)"; 478 | SWIFT_VERSION = 5.0; 479 | TARGETED_DEVICE_FAMILY = "1,2"; 480 | }; 481 | name = Release; 482 | }; 483 | 5E4508EF2315053000FFE1E0 /* Debug */ = { 484 | isa = XCBuildConfiguration; 485 | buildSettings = { 486 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 487 | BUNDLE_LOADER = "$(TEST_HOST)"; 488 | CODE_SIGN_STYLE = Automatic; 489 | DEVELOPMENT_TEAM = X496RVQDTB; 490 | INFOPLIST_FILE = XLCardSwitchExampleTests/Info.plist; 491 | LD_RUNPATH_SEARCH_PATHS = ( 492 | "$(inherited)", 493 | "@executable_path/Frameworks", 494 | "@loader_path/Frameworks", 495 | ); 496 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchExampleTests; 497 | PRODUCT_NAME = "$(TARGET_NAME)"; 498 | SWIFT_VERSION = 5.0; 499 | TARGETED_DEVICE_FAMILY = "1,2"; 500 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/XLCardSwitchExample.app/XLCardSwitchExample"; 501 | }; 502 | name = Debug; 503 | }; 504 | 5E4508F02315053000FFE1E0 /* Release */ = { 505 | isa = XCBuildConfiguration; 506 | buildSettings = { 507 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 508 | BUNDLE_LOADER = "$(TEST_HOST)"; 509 | CODE_SIGN_STYLE = Automatic; 510 | DEVELOPMENT_TEAM = X496RVQDTB; 511 | INFOPLIST_FILE = XLCardSwitchExampleTests/Info.plist; 512 | LD_RUNPATH_SEARCH_PATHS = ( 513 | "$(inherited)", 514 | "@executable_path/Frameworks", 515 | "@loader_path/Frameworks", 516 | ); 517 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchExampleTests; 518 | PRODUCT_NAME = "$(TARGET_NAME)"; 519 | SWIFT_VERSION = 5.0; 520 | TARGETED_DEVICE_FAMILY = "1,2"; 521 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/XLCardSwitchExample.app/XLCardSwitchExample"; 522 | }; 523 | name = Release; 524 | }; 525 | 5E4508F22315053000FFE1E0 /* Debug */ = { 526 | isa = XCBuildConfiguration; 527 | buildSettings = { 528 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 529 | CODE_SIGN_STYLE = Automatic; 530 | DEVELOPMENT_TEAM = X496RVQDTB; 531 | INFOPLIST_FILE = XLCardSwitchExampleUITests/Info.plist; 532 | LD_RUNPATH_SEARCH_PATHS = ( 533 | "$(inherited)", 534 | "@executable_path/Frameworks", 535 | "@loader_path/Frameworks", 536 | ); 537 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchExampleUITests; 538 | PRODUCT_NAME = "$(TARGET_NAME)"; 539 | SWIFT_VERSION = 5.0; 540 | TARGETED_DEVICE_FAMILY = "1,2"; 541 | TEST_TARGET_NAME = XLCardSwitchExample; 542 | }; 543 | name = Debug; 544 | }; 545 | 5E4508F32315053000FFE1E0 /* Release */ = { 546 | isa = XCBuildConfiguration; 547 | buildSettings = { 548 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 549 | CODE_SIGN_STYLE = Automatic; 550 | DEVELOPMENT_TEAM = X496RVQDTB; 551 | INFOPLIST_FILE = XLCardSwitchExampleUITests/Info.plist; 552 | LD_RUNPATH_SEARCH_PATHS = ( 553 | "$(inherited)", 554 | "@executable_path/Frameworks", 555 | "@loader_path/Frameworks", 556 | ); 557 | PRODUCT_BUNDLE_IDENTIFIER = mxl.XLCardSwitchExampleUITests; 558 | PRODUCT_NAME = "$(TARGET_NAME)"; 559 | SWIFT_VERSION = 5.0; 560 | TARGETED_DEVICE_FAMILY = "1,2"; 561 | TEST_TARGET_NAME = XLCardSwitchExample; 562 | }; 563 | name = Release; 564 | }; 565 | /* End XCBuildConfiguration section */ 566 | 567 | /* Begin XCConfigurationList section */ 568 | 5E4508BE2315052E00FFE1E0 /* Build configuration list for PBXProject "XLCardSwitchExample" */ = { 569 | isa = XCConfigurationList; 570 | buildConfigurations = ( 571 | 5E4508E92315053000FFE1E0 /* Debug */, 572 | 5E4508EA2315053000FFE1E0 /* Release */, 573 | ); 574 | defaultConfigurationIsVisible = 0; 575 | defaultConfigurationName = Release; 576 | }; 577 | 5E4508EB2315053000FFE1E0 /* Build configuration list for PBXNativeTarget "XLCardSwitchExample" */ = { 578 | isa = XCConfigurationList; 579 | buildConfigurations = ( 580 | 5E4508EC2315053000FFE1E0 /* Debug */, 581 | 5E4508ED2315053000FFE1E0 /* Release */, 582 | ); 583 | defaultConfigurationIsVisible = 0; 584 | defaultConfigurationName = Release; 585 | }; 586 | 5E4508EE2315053000FFE1E0 /* Build configuration list for PBXNativeTarget "XLCardSwitchExampleTests" */ = { 587 | isa = XCConfigurationList; 588 | buildConfigurations = ( 589 | 5E4508EF2315053000FFE1E0 /* Debug */, 590 | 5E4508F02315053000FFE1E0 /* Release */, 591 | ); 592 | defaultConfigurationIsVisible = 0; 593 | defaultConfigurationName = Release; 594 | }; 595 | 5E4508F12315053000FFE1E0 /* Build configuration list for PBXNativeTarget "XLCardSwitchExampleUITests" */ = { 596 | isa = XCConfigurationList; 597 | buildConfigurations = ( 598 | 5E4508F22315053000FFE1E0 /* Debug */, 599 | 5E4508F32315053000FFE1E0 /* Release */, 600 | ); 601 | defaultConfigurationIsVisible = 0; 602 | defaultConfigurationName = Release; 603 | }; 604 | /* End XCConfigurationList section */ 605 | }; 606 | rootObject = 5E4508BB2315052E00FFE1E0 /* Project object */; 607 | } 608 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.xcworkspace/xcuserdata/MengXianLiang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.xcworkspace/xcuserdata/MengXianLiang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.xcworkspace/xcuserdata/mxl.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/project.xcworkspace/xcuserdata/mxl.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/xcuserdata/MengXianLiang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 12 | 13 | 14 | 16 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/xcuserdata/MengXianLiang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | XLCardSwitchExample.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample.xcodeproj/xcuserdata/mxl.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | XLCardSwitchExample.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // XLCardSwitchExample 4 | // 5 | // Created by MengXianLiang on 2019/8/27. 6 | // Copyright © 2019 mxl. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | let nav = UINavigationController.init(rootViewController: ViewController()) 19 | self.window?.rootViewController = nav 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | } 27 | 28 | func applicationDidEnterBackground(_ application: UIApplication) { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | func applicationWillEnterForeground(_ application: UIApplication) { 34 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | func applicationDidBecomeActive(_ application: UIApplication) { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | func applicationWillTerminate(_ application: UIApplication) { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/1.imageset/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/1.imageset/1.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/10.imageset/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/10.imageset/10.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/10.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "10.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/11.imageset/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/11.imageset/11.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/11.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "11.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/12.imageset/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/12.imageset/12.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/12.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "12.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/13.imageset/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/13.imageset/13.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/13.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "13.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/2.imageset/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/2.imageset/2.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "2.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/3.imageset/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/3.imageset/3.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "3.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/4.imageset/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/4.imageset/4.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "4.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/5.imageset/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/5.imageset/5.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/5.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "5.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/6.imageset/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/6.imageset/6.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/6.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "6.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/7.imageset/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/7.imageset/7.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/7.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "7.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/8.imageset/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/8.imageset/8.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/8.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "8.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/9.imageset/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mengxianliang/XLCardSwitch/d8d7249b9ed6f1afa716c9545e587f33eba057fd/XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/9.imageset/9.png -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/9.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "9.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Assets.xcassets/TestImages/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/CustomCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomCollectionViewCell.swift 3 | // XLCardSwitchExample 4 | // 5 | // Created by MengXianLiang on 2019/8/28. 6 | // Copyright © 2019 mxl. All rights reserved. 7 | // 自定义cell 8 | 9 | import UIKit 10 | 11 | class CustomCollectionViewCell: UICollectionViewCell { 12 | 13 | var textLabel = UILabel() 14 | var imageView = UIImageView() 15 | 16 | required init?(coder aDecoder: NSCoder) { 17 | super.init(coder: aDecoder) 18 | } 19 | 20 | override init(frame: CGRect) { 21 | super.init(frame: frame) 22 | initUI() 23 | } 24 | 25 | func initUI() { 26 | layer.cornerRadius = 10.0 27 | layer.masksToBounds = true 28 | backgroundColor = UIColor.white 29 | 30 | let imageH = bounds.size.height*0.8 31 | let labelH = bounds.size.height*0.2 32 | 33 | 34 | imageView.frame = CGRect(x: 0, y: 0, width: bounds.size.width, height: imageH) 35 | imageView.contentMode = UIView.ContentMode.scaleAspectFill 36 | imageView.layer.masksToBounds = true 37 | addSubview(imageView) 38 | 39 | 40 | textLabel.frame = CGRect(x: 0, y: imageH, width: bounds.size.width, height: labelH) 41 | textLabel.textColor = UIColor(red: 102.0/255.0, green: 102.0/255.0, blue: 102.0/255.0, alpha: 1) 42 | textLabel.font = UIFont.systemFont(ofSize: 22) 43 | textLabel.textAlignment = NSTextAlignment.center; 44 | textLabel.adjustsFontSizeToFitWidth = true; 45 | addSubview(textLabel) 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // XLCardSwitchExample 4 | // 5 | // Created by MengXianLiang on 2019/8/27. 6 | // Copyright © 2019 mxl. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController,XLCardSwitchDataSource,XLCardSwitchDelegate { 12 | //背景图 13 | var imageView = UIImageView() 14 | //毛玻璃效果 15 | var blurEffectView = UIVisualEffectView() 16 | //滚动卡片 17 | lazy var cardSwitch: XLCardSwitch = { 18 | let temp = XLCardSwitch() 19 | temp.frame = self.view.bounds 20 | temp.dataSource = self 21 | temp.delegate = self 22 | //注册cell 23 | temp.register(cellClass: CustomCollectionViewCell.self, forCellWithReuseIdentifier:"CustomCellID") 24 | return temp 25 | }() 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | self.buildUI() 30 | } 31 | 32 | func buildUI() { 33 | //添加其他部分 34 | self.buildOtherUI() 35 | //添加cardSwitch 36 | self.view.addSubview(self.cardSwitch) 37 | } 38 | 39 | //自动布局 40 | override func viewDidLayoutSubviews() { 41 | super.viewDidLayoutSubviews() 42 | self.imageView.frame = self.view.bounds 43 | self.blurEffectView.frame = self.view.bounds 44 | self.cardSwitch.frame = self.view.bounds 45 | } 46 | 47 | func buildOtherUI() { 48 | //设置背景色 49 | self.view.backgroundColor = UIColor.white 50 | 51 | //设置navigationBar 52 | self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Previous", style: UIBarButtonItem.Style.plain, target: self, action: #selector(switchPrevious)) 53 | 54 | self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: UIBarButtonItem.Style.plain, target: self, action: #selector(switchNext)) 55 | 56 | let seg = UISegmentedControl(items: ["正常滚动","自动居中"]) 57 | seg.selectedSegmentIndex = 0 58 | seg.addTarget(self, action: #selector(segMethod(seg:)), for: UIControl.Event.valueChanged) 59 | self.navigationItem.titleView = seg 60 | 61 | //设置默认背景图片 62 | self.imageView.image = UIImage(named: self.cellInfoArr()[0].0) 63 | self.view.addSubview(self.imageView) 64 | 65 | let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.light) 66 | self.blurEffectView.effect = blurEffect; 67 | self.blurEffectView.frame = self.imageView.bounds 68 | self.imageView.addSubview(blurEffectView) 69 | } 70 | 71 | //DataSource方法,返回总共卡片个数 72 | func cardSwitchNumberOfCard() -> (Int) { 73 | return self.cellInfoArr().count 74 | } 75 | 76 | //DataSource方法,返回UICollectionViewCell 77 | func cardSwitchCellForItemAtIndex(index: Int) -> UICollectionViewCell { 78 | let cell = self.cardSwitch.dequeueReusableCell(withReuseIdentifier:"CustomCellID", for: index) as! CustomCollectionViewCell 79 | cell.imageView.image = UIImage(named: self.cellInfoArr()[index].0) 80 | cell.textLabel.text = self.cellInfoArr()[index].1 81 | return cell 82 | } 83 | 84 | //代理方法 85 | //切换到了卡片 86 | func cardSwitchDidScrollToIndex(index: Int) { 87 | self.imageView.image = UIImage(named: self.cellInfoArr()[index].0) 88 | } 89 | //点击了卡片 90 | func cardSwitchDidSelectedAtIndex(index: Int) { 91 | print("点击了卡片-\(index)") 92 | } 93 | 94 | //MARK- 95 | //MARK其他方法 96 | @objc func switchPrevious() { 97 | self.cardSwitch.switchPrevious() 98 | } 99 | 100 | @objc func switchNext() { 101 | self.cardSwitch.switchNext() 102 | } 103 | 104 | @objc func segMethod(seg: UISegmentedControl) { 105 | self.cardSwitch.pagingEnabled = (seg.selectedSegmentIndex == 1) 106 | } 107 | 108 | //MARK:- 109 | //MARK:测试数据 (图片名称,名字) 110 | func cellInfoArr() -> Array<(String, String)> { 111 | return [("1","艾德·史塔克"),("2","凯瑟琳·徒利·史塔克"),("3","罗柏·史塔克"),("4","琼恩·雪诺"),("5","艾莉亚·史塔克"),("6","珊莎·史塔克"),("7","布兰·史塔克"),("8","瑟曦·兰尼斯特·拜拉席恩"),("9","提利昂·兰尼斯特"),("10","泰温·兰尼斯特"),("11","詹姆·兰尼斯特"),("12","乔佛里·拜拉席恩"),("13","丹尼莉丝·坦格利安")] 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExampleTests/XLCardSwitchExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitchExampleTests.swift 3 | // XLCardSwitchExampleTests 4 | // 5 | // Created by MengXianLiang on 2019/8/27. 6 | // Copyright © 2019 mxl. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import XLCardSwitchExample 11 | 12 | class XLCardSwitchExampleTests: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func testExample() { 23 | // This is an example of a functional test case. 24 | // Use XCTAssert and related functions to verify your tests produce the correct results. 25 | } 26 | 27 | func testPerformanceExample() { 28 | // This is an example of a performance test case. 29 | self.measure { 30 | // Put the code you want to measure the time of here. 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExampleUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /XLCardSwitchExample-Swift/XLCardSwitchExampleUITests/XLCardSwitchExampleUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // XLCardSwitchExampleUITests.swift 3 | // XLCardSwitchExampleUITests 4 | // 5 | // Created by MengXianLiang on 2019/8/27. 6 | // Copyright © 2019 mxl. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class XLCardSwitchExampleUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | // Put setup code here. This method is called before the invocation of each test method in the class. 15 | 16 | // In UI tests it is usually best to stop immediately when a failure occurs. 17 | continueAfterFailure = false 18 | 19 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 20 | XCUIApplication().launch() 21 | 22 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 23 | } 24 | 25 | override func tearDown() { 26 | // Put teardown code here. This method is called after the invocation of each test method in the class. 27 | } 28 | 29 | func testExample() { 30 | // Use recording to get started writing UI tests. 31 | // Use XCTAssert and related functions to verify your tests produce the correct results. 32 | } 33 | 34 | } 35 | --------------------------------------------------------------------------------