Swift style refraction; Rename 'pagingDistance' property of FSPagerView to 'decelerationDistance'.
This commit is contained in:
parent
45f1a6c11b
commit
6b54500113
|
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
F931E00C2158A1F3001B2A01 /* FSPagerViewObjcCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = F931E00B2158A1F3001B2A01 /* FSPagerViewObjcCompat.m */; };
|
||||
F954839A1E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */; };
|
||||
F954839B1E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */; };
|
||||
F9580B571E5D995400C5B267 /* FSPageControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B511E5D995400C5B267 /* FSPageControl.swift */; };
|
||||
|
|
@ -44,6 +45,7 @@
|
|||
|
||||
/* Begin PBXFileReference section */
|
||||
50989DFE2151DB29004DBB4A /* FSPagerViewObjcCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSPagerViewObjcCompat.h; sourceTree = "<group>"; };
|
||||
F931E00B2158A1F3001B2A01 /* FSPagerViewObjcCompat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSPagerViewObjcCompat.m; sourceTree = "<group>"; };
|
||||
F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPagerViewLayoutAttributes.swift; sourceTree = "<group>"; };
|
||||
F9580B511E5D995400C5B267 /* FSPageControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPageControl.swift; sourceTree = "<group>"; };
|
||||
F9580B521E5D995400C5B267 /* FSPagerCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPagerCollectionView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -101,6 +103,7 @@
|
|||
F9580B561E5D995400C5B267 /* FSPageViewTransformer.swift */,
|
||||
F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */,
|
||||
50989DFE2151DB29004DBB4A /* FSPagerViewObjcCompat.h */,
|
||||
F931E00B2158A1F3001B2A01 /* FSPagerViewObjcCompat.m */,
|
||||
);
|
||||
name = Sources;
|
||||
path = ../Sources;
|
||||
|
|
@ -298,6 +301,7 @@
|
|||
F9C694331E40C583007084B6 /* BasicExampleViewController.swift in Sources */,
|
||||
F9580B5A1E5D995400C5B267 /* FSPagerViewCell.swift in Sources */,
|
||||
F9580B5B1E5D995400C5B267 /* FSPageViewLayout.swift in Sources */,
|
||||
F931E00C2158A1F3001B2A01 /* FSPagerViewObjcCompat.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable
|
|||
|
||||
fileprivate let sectionTitles = ["Configurations", "Paging Distance", "Item Size", "Interitem Spacing", "Number Of Items"]
|
||||
fileprivate let configurationTitles = ["Automatic sliding","Infinite"]
|
||||
fileprivate let pagingDistanceOptions = ["Automatic", "1", "2"]
|
||||
fileprivate let decelerationDistanceOptions = ["Automatic", "1", "2"]
|
||||
fileprivate let imageNames = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg"]
|
||||
fileprivate var numberOfItems = 7
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable
|
|||
@IBOutlet weak var pagerView: FSPagerView! {
|
||||
didSet {
|
||||
self.pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
|
||||
self.pagerView.itemSize = .zero
|
||||
self.pagerView.itemSize = FSPagerView.automaticSize
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,13 +38,12 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable
|
|||
return self.sectionTitles.count
|
||||
}
|
||||
|
||||
@available(iOS 2.0, *)
|
||||
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
switch section {
|
||||
case 0:
|
||||
return self.configurationTitles.count
|
||||
case 1:
|
||||
return self.pagingDistanceOptions.count
|
||||
return self.decelerationDistanceOptions.count
|
||||
case 2,3,4:
|
||||
return 1
|
||||
default:
|
||||
|
|
@ -69,14 +68,14 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable
|
|||
case 1:
|
||||
// Paging Distance
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
|
||||
cell.textLabel?.text = self.pagingDistanceOptions[indexPath.row]
|
||||
cell.textLabel?.text = self.decelerationDistanceOptions[indexPath.row]
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
cell.accessoryType = self.pagerView.pagingDistance == FSPagerViewAutomaticPagingDistance ? .checkmark : .none
|
||||
cell.accessoryType = self.pagerView.decelerationDistance == FSPagerView.automaticDistance ? .checkmark : .none
|
||||
case 1:
|
||||
cell.accessoryType = self.pagerView.pagingDistance == 1 ? .checkmark : .none
|
||||
cell.accessoryType = self.pagerView.decelerationDistance == 1 ? .checkmark : .none
|
||||
case 2:
|
||||
cell.accessoryType = self.pagerView.pagingDistance == 2 ? .checkmark : .none
|
||||
cell.accessoryType = self.pagerView.decelerationDistance == 2 ? .checkmark : .none
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -136,11 +135,11 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable
|
|||
case 1:
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance
|
||||
self.pagerView.decelerationDistance = FSPagerView.automaticDistance
|
||||
case 1:
|
||||
self.pagerView.pagingDistance = 1
|
||||
self.pagerView.decelerationDistance = 1
|
||||
case 2:
|
||||
self.pagerView.pagingDistance = 2
|
||||
self.pagerView.decelerationDistance = 2
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,22 +27,22 @@ class TransformerExampleViewController: UIViewController,FSPagerViewDataSource,F
|
|||
self.pagerView.transformer = FSPagerViewTransformer(type:type)
|
||||
switch type {
|
||||
case .crossFading, .zoomOut, .depth:
|
||||
self.pagerView.itemSize = .zero // 'Zero' means fill the size of parent
|
||||
self.pagerView.pagingDistance = 1
|
||||
self.pagerView.itemSize = FSPagerView.automaticSize
|
||||
self.pagerView.decelerationDistance = 1
|
||||
case .linear, .overlap:
|
||||
let transform = CGAffineTransform(scaleX: 0.6, y: 0.75)
|
||||
self.pagerView.itemSize = self.pagerView.frame.size.applying(transform)
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance
|
||||
self.pagerView.decelerationDistance = FSPagerView.automaticDistance
|
||||
case .ferrisWheel, .invertedFerrisWheel:
|
||||
self.pagerView.itemSize = CGSize(width: 180, height: 140)
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance
|
||||
self.pagerView.decelerationDistance = FSPagerView.automaticDistance
|
||||
case .coverFlow:
|
||||
self.pagerView.itemSize = CGSize(width: 220, height: 170)
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance
|
||||
self.pagerView.decelerationDistance = FSPagerView.automaticDistance
|
||||
case .cubic:
|
||||
let transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
||||
self.pagerView.itemSize = self.pagerView.frame.size.applying(transform)
|
||||
self.pagerView.pagingDistance = 1
|
||||
self.pagerView.decelerationDistance = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,5 +113,3 @@ class TransformerExampleViewController: UIViewController,FSPagerViewDataSource,F
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
/* Begin PBXBuildFile section */
|
||||
50C44A1D2150E7800093B3E9 /* FSPagerViewObjcCompat.h in Headers */ = {isa = PBXBuildFile; fileRef = 50C44A1C2150E7800093B3E9 /* FSPagerViewObjcCompat.h */; };
|
||||
F931E0062158A062001B2A01 /* FSPagerViewObjcCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = F931E0052158A062001B2A01 /* FSPagerViewObjcCompat.m */; };
|
||||
F9580B7B1E5D9F0600C5B267 /* FSPagerView.h in Headers */ = {isa = PBXBuildFile; fileRef = F9580B791E5D9F0600C5B267 /* FSPagerView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
F9580B881E5D9F2B00C5B267 /* FSPageControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B821E5D9F2B00C5B267 /* FSPageControl.swift */; };
|
||||
F9580B891E5D9F2B00C5B267 /* FSPagerCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B831E5D9F2B00C5B267 /* FSPagerCollectionView.swift */; };
|
||||
|
|
@ -20,6 +21,7 @@
|
|||
|
||||
/* Begin PBXFileReference section */
|
||||
50C44A1C2150E7800093B3E9 /* FSPagerViewObjcCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSPagerViewObjcCompat.h; sourceTree = "<group>"; };
|
||||
F931E0052158A062001B2A01 /* FSPagerViewObjcCompat.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FSPagerViewObjcCompat.m; sourceTree = "<group>"; };
|
||||
F9580B761E5D9F0600C5B267 /* FSPagerView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FSPagerView.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F9580B791E5D9F0600C5B267 /* FSPagerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSPagerView.h; sourceTree = "<group>"; };
|
||||
F9580B7A1E5D9F0600C5B267 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
|
@ -80,6 +82,7 @@
|
|||
F9D7BD291E63DD5F003F6A0E /* FSPagerViewLayoutAttributes.swift */,
|
||||
F9580B871E5D9F2B00C5B267 /* FSPageViewTransformer.swift */,
|
||||
50C44A1C2150E7800093B3E9 /* FSPagerViewObjcCompat.h */,
|
||||
F931E0052158A062001B2A01 /* FSPagerViewObjcCompat.m */,
|
||||
);
|
||||
name = Sources;
|
||||
path = ../Sources;
|
||||
|
|
@ -174,6 +177,7 @@
|
|||
F9580B8C1E5D9F2B00C5B267 /* FSPageViewLayout.swift in Sources */,
|
||||
F9580B8A1E5D9F2B00C5B267 /* FSPagerView.swift in Sources */,
|
||||
F9580B8B1E5D9F2B00C5B267 /* FSPagerViewCell.swift in Sources */,
|
||||
F931E0062158A062001B2A01 /* FSPagerViewObjcCompat.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
F908BC4C1E35AAE4002B2F51 /* 5.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F908BC3D1E35AAE4002B2F51 /* 5.jpg */; };
|
||||
F908BC4D1E35AAE4002B2F51 /* 6.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F908BC3E1E35AAE4002B2F51 /* 6.jpg */; };
|
||||
F908BC4E1E35AAE4002B2F51 /* 7.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F908BC3F1E35AAE4002B2F51 /* 7.jpg */; };
|
||||
F931E00A2158A1E4001B2A01 /* FSPagerViewObjcCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = F931E0092158A1E4001B2A01 /* FSPagerViewObjcCompat.m */; };
|
||||
F93F5E141E319AE8006B7082 /* PageControlExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F93F5E131E319AE8006B7082 /* PageControlExampleViewController.m */; };
|
||||
F9580B641E5D997200C5B267 /* FSPageControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B5E1E5D997200C5B267 /* FSPageControl.swift */; };
|
||||
F9580B651E5D997200C5B267 /* FSPagerCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B5F1E5D997200C5B267 /* FSPagerCollectionView.swift */; };
|
||||
|
|
@ -52,6 +53,7 @@
|
|||
F908BC3D1E35AAE4002B2F51 /* 5.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 5.jpg; sourceTree = "<group>"; };
|
||||
F908BC3E1E35AAE4002B2F51 /* 6.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 6.jpg; sourceTree = "<group>"; };
|
||||
F908BC3F1E35AAE4002B2F51 /* 7.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 7.jpg; sourceTree = "<group>"; };
|
||||
F931E0092158A1E4001B2A01 /* FSPagerViewObjcCompat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSPagerViewObjcCompat.m; sourceTree = "<group>"; };
|
||||
F93F5E121E319AE8006B7082 /* PageControlExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageControlExampleViewController.h; sourceTree = "<group>"; };
|
||||
F93F5E131E319AE8006B7082 /* PageControlExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PageControlExampleViewController.m; sourceTree = "<group>"; };
|
||||
F9580B5E1E5D997200C5B267 /* FSPageControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPageControl.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -123,6 +125,7 @@
|
|||
F9FF349E1E65B38C001E943F /* FSPagerViewLayoutAttributes.swift */,
|
||||
F9580B631E5D997200C5B267 /* FSPageViewTransformer.swift */,
|
||||
50989DFD2151DB25004DBB4A /* FSPagerViewObjcCompat.h */,
|
||||
F931E0092158A1E4001B2A01 /* FSPagerViewObjcCompat.m */,
|
||||
);
|
||||
name = Sources;
|
||||
path = ../Sources;
|
||||
|
|
@ -343,6 +346,7 @@
|
|||
F93F5E141E319AE8006B7082 /* PageControlExampleViewController.m in Sources */,
|
||||
F9EC371E1E304A830022B6D6 /* main.m in Sources */,
|
||||
F9580B661E5D997200C5B267 /* FSPagerView.swift in Sources */,
|
||||
F931E00A2158A1E4001B2A01 /* FSPagerViewObjcCompat.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
@property (strong, nonatomic) NSArray<NSString *> *sectionTitles;
|
||||
@property (strong, nonatomic) NSArray<NSString *> *configurationTitles;
|
||||
@property (strong, nonatomic) NSArray<NSString *> *pagingDistanceOptions;
|
||||
@property (strong, nonatomic) NSArray<NSString *> *decelerationDistanceOptions;
|
||||
@property (strong, nonatomic) NSArray<NSString *> *imageNames;
|
||||
@property (assign, nonatomic) NSInteger numberOfItems;
|
||||
|
||||
|
|
@ -34,14 +34,14 @@
|
|||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
self.sectionTitles = @[@"Configurations", @"Paging Distance", @"Item Size", @"Interitem Spacing", @"Number Of Items"];
|
||||
self.sectionTitles = @[@"Configurations", @"Deceleration Distance", @"Item Size", @"Interitem Spacing", @"Number Of Items"];
|
||||
self.configurationTitles = @[@"Automatic sliding", @"Infinite"];
|
||||
self.pagingDistanceOptions = @[@"Automatic", @"1", @"2"];
|
||||
self.decelerationDistanceOptions = @[@"Automatic", @"1", @"2"];
|
||||
self.imageNames = @[@"1.jpg", @"2.jpg", @"3.jpg", @"4.jpg", @"5.jpg", @"6.jpg", @"7.jpg"];
|
||||
self.numberOfItems = 7;
|
||||
|
||||
[self.pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"];
|
||||
self.pagerView.itemSize = CGSizeZero;
|
||||
self.pagerView.itemSize = FSPagerViewAutomaticSize;
|
||||
self.pageControl.numberOfPages = self.imageNames.count;
|
||||
self.pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
|
||||
self.pageControl.contentInsets = UIEdgeInsetsMake(0, 20, 0, 20);
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
case 0:
|
||||
return self.configurationTitles.count;
|
||||
case 1:
|
||||
return self.pagingDistanceOptions.count;
|
||||
return self.decelerationDistanceOptions.count;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
|
|
@ -91,17 +91,17 @@
|
|||
case 1: {
|
||||
// Paging Distance
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
|
||||
cell.textLabel.text = self.pagingDistanceOptions[indexPath.row];
|
||||
cell.textLabel.text = self.decelerationDistanceOptions[indexPath.row];
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
// Hardcode like '-1' is bad for readability, but there haven't been a better solution to export a swift constant to objective-c yet.
|
||||
cell.accessoryType = self.pagerView.pagingDistance == FSPagerViewAutomaticPagingDistance ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
||||
cell.accessoryType = self.pagerView.decelerationDistance == FSPagerViewAutomaticDistance ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
||||
break;
|
||||
case 1:
|
||||
cell.accessoryType = self.pagerView.pagingDistance == 1 ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
||||
cell.accessoryType = self.pagerView.decelerationDistance == 1 ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
||||
break;
|
||||
case 2:
|
||||
cell.accessoryType = self.pagerView.pagingDistance == 2 ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
||||
cell.accessoryType = self.pagerView.decelerationDistance == 2 ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -172,13 +172,13 @@
|
|||
case 1: {
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance;
|
||||
self.pagerView.decelerationDistance = FSPagerViewAutomaticDistance;
|
||||
break;
|
||||
case 1:
|
||||
self.pagerView.pagingDistance = 1;
|
||||
self.pagerView.decelerationDistance = 1;
|
||||
break;
|
||||
case 2:
|
||||
self.pagerView.pagingDistance = 2;
|
||||
self.pagerView.decelerationDistance = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#import "PageControlExampleViewController.h"
|
||||
#import "FSPagerViewExample_Objc-Swift.h"
|
||||
#import "FSPagerViewObjcCompat.h"
|
||||
|
||||
@interface PageControlExampleViewController () <UITableViewDataSource,UITableViewDelegate,FSPagerViewDataSource,FSPagerViewDelegate>
|
||||
|
||||
|
|
@ -48,7 +49,7 @@
|
|||
self.pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
|
||||
self.pageControl.contentInsets = UIEdgeInsetsMake(0, 20, 0, 20);
|
||||
|
||||
self.pagerView.itemSize = CGSizeZero; // Fill parent
|
||||
self.pagerView.itemSize = FSPagerViewAutomaticSize; // Fill parent
|
||||
[self.pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,32 +149,32 @@
|
|||
case FSPagerViewTransformerTypeCrossFading:
|
||||
case FSPagerViewTransformerTypeZoomOut:
|
||||
case FSPagerViewTransformerTypeDepth: {
|
||||
self.pagerView.itemSize = CGSizeZero; // 'Zero' means fill the size of parent
|
||||
self.pagerView.pagingDistance = 1;
|
||||
self.pagerView.itemSize = FSPagerViewAutomaticSize;
|
||||
self.pagerView.decelerationDistance = 1;
|
||||
break;
|
||||
}
|
||||
case FSPagerViewTransformerTypeLinear:
|
||||
case FSPagerViewTransformerTypeOverlap: {
|
||||
CGAffineTransform transform = CGAffineTransformMakeScale(0.6, 0.75);
|
||||
self.pagerView.itemSize = CGSizeApplyAffineTransform(self.pagerView.frame.size, transform);
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance;
|
||||
self.pagerView.decelerationDistance = FSPagerViewAutomaticDistance;
|
||||
break;
|
||||
}
|
||||
case FSPagerViewTransformerTypeFerrisWheel:
|
||||
case FSPagerViewTransformerTypeInvertedFerrisWheel: {
|
||||
self.pagerView.itemSize = CGSizeMake(180, 140);
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance;
|
||||
self.pagerView.decelerationDistance = FSPagerViewAutomaticDistance;
|
||||
break;
|
||||
}
|
||||
case FSPagerViewTransformerTypeCoverFlow: {
|
||||
self.pagerView.itemSize = CGSizeMake(220, 170);
|
||||
self.pagerView.pagingDistance = FSPagerViewAutomaticPagingDistance;
|
||||
self.pagerView.decelerationDistance = FSPagerViewAutomaticDistance;
|
||||
break;
|
||||
}
|
||||
case FSPagerViewTransformerTypeCubic: {
|
||||
CGAffineTransform transform = CGAffineTransformMakeScale(0.9, 0.9);
|
||||
self.pagerView.itemSize = CGSizeApplyAffineTransform(self.pagerView.frame.size, transform);
|
||||
self.pagerView.pagingDistance = 1;
|
||||
self.pagerView.decelerationDistance = 1;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ class FSPagerViewLayout: UICollectionViewLayout {
|
|||
|
||||
func calculateTargetOffset(by proposedOffset: CGFloat, touchedOffset: CGFloat, boundedOffset: CGFloat) -> CGFloat {
|
||||
var targetOffset: CGFloat
|
||||
if pagerView.pagingDistance == FSPagerViewAutomaticPagingDistance {
|
||||
if pagerView.decelerationDistance == FSPagerView.automaticDistance {
|
||||
if abs(velocity.x) >= 0.3 {
|
||||
let vector: CGFloat = velocity.x >= 0 ? 1.0 : -1.0
|
||||
targetOffset = round(proposedOffset/self.itemSpacing+0.35*vector) * self.itemSpacing // Ceil by 0.15, rather than 0.5
|
||||
|
|
@ -167,7 +167,7 @@ class FSPagerViewLayout: UICollectionViewLayout {
|
|||
targetOffset = round(proposedOffset/self.itemSpacing) * self.itemSpacing
|
||||
}
|
||||
} else {
|
||||
let extraDistance = max(pagerView.pagingDistance-1, 0)
|
||||
let extraDistance = max(pagerView.decelerationDistance-1, 0)
|
||||
switch velocity.x {
|
||||
case 0.3 ... CGFloat.greatestFiniteMagnitude:
|
||||
targetOffset = ceil(touchedOffset/self.itemSpacing+CGFloat(extraDistance)) * self.itemSpacing
|
||||
|
|
|
|||
|
|
@ -74,18 +74,6 @@ public protocol FSPagerViewDelegate: NSObjectProtocol {
|
|||
|
||||
}
|
||||
|
||||
/// Constants indicating the direction of scrolling for the pager view.
|
||||
@objc
|
||||
public enum FSPagerViewScrollDirection: Int {
|
||||
/// The pager view scrolls content horizontally
|
||||
case horizontal
|
||||
/// The pager view scrolls content vertically
|
||||
case vertical
|
||||
}
|
||||
|
||||
/// The paging distance is automatically calculated according to the scrolling speed of the pager view.
|
||||
public let FSPagerViewAutomaticPagingDistance: UInt = 0
|
||||
|
||||
@IBDesignable
|
||||
open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelegate {
|
||||
|
||||
|
|
@ -99,7 +87,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
|
|||
|
||||
/// The scroll direction of the pager view. Default is horizontal.
|
||||
@objc
|
||||
open var scrollDirection: FSPagerViewScrollDirection = .horizontal {
|
||||
open var scrollDirection: FSPagerView.ScrollDirection = .horizontal {
|
||||
didSet {
|
||||
self.collectionViewLayout.forceInvalidate()
|
||||
}
|
||||
|
|
@ -124,9 +112,9 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
|
|||
}
|
||||
}
|
||||
|
||||
/// The item size of the pager view. When the value of this property is .zero, the items fill the entire visible area of the pager view. Default is .zero.
|
||||
/// The item size of the pager view. When the value of this property is .automaticSize, the items fill the entire visible area of the pager view. Default is .automaticSize.
|
||||
@IBInspectable
|
||||
open var itemSize: CGSize = .zero {
|
||||
open var itemSize: CGSize = automaticSize {
|
||||
didSet {
|
||||
self.collectionViewLayout.forceInvalidate()
|
||||
}
|
||||
|
|
@ -141,9 +129,9 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
|
|||
}
|
||||
}
|
||||
|
||||
/// An unsigned integer value that determines the paging distance of the pager view, which indicates the number of passing items during a single paging. When the value of this property is FSPagerViewAutomaticPagingDistance(0), the actual 'distance' is automatically calculated according to the scrolling speed of the pager view. Default is 1.
|
||||
/// An unsigned integer value that determines the paging distance of the pager view, which indicates the number of passing items during the deceleration. When the value of this property is FSPagerView.automaticDistance(0), the actual 'distance' is automatically calculated according to the scrolling speed of the pager view. Default is 1.
|
||||
@IBInspectable
|
||||
open var pagingDistance: UInt = 1
|
||||
open var decelerationDistance: UInt = 1
|
||||
|
||||
/// A Boolean value that controls whether the pager view bounces past the edge of content and back again.
|
||||
@IBInspectable
|
||||
|
|
@ -606,3 +594,22 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
extension FSPagerView {
|
||||
|
||||
/// Constants indicating the direction of scrolling for the pager view.
|
||||
@objc
|
||||
public enum ScrollDirection: Int {
|
||||
/// The pager view scrolls content horizontally
|
||||
case horizontal
|
||||
/// The pager view scrolls content vertically
|
||||
case vertical
|
||||
}
|
||||
|
||||
/// Requests that FSPagerView use the default value for a given distance.
|
||||
public static let automaticDistance: UInt = 0
|
||||
|
||||
/// Requests that FSPagerView use the default value for a given size.
|
||||
public static let automaticSize: CGSize = .zero
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,13 @@
|
|||
// Copyright © 2018 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
|
||||
#define FSPagerViewAutomaticPagingDistance 0
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
/// Requests that FSPagerView use the default value for a given distance.
|
||||
extern NSUInteger const FSPagerViewAutomaticDistance;
|
||||
|
||||
/// Requests that FSPagerView use the default value for a given size.
|
||||
extern CGSize const FSPagerViewAutomaticSize;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
//
|
||||
// FSPagerViewObjcCompat.m
|
||||
// FSPagerView
|
||||
//
|
||||
// Created by Wenchao Ding on 2018/9/24.
|
||||
// Copyright © 2018 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FSPagerViewObjcCompat.h"
|
||||
|
||||
NSUInteger const FSPagerViewAutomaticDistance = 0;
|
||||
CGSize const FSPagerViewAutomaticSize = { .width = 0, .height = 0 };
|
||||
Loading…
Reference in New Issue