Skip to content

Commit 298220c

Browse files
committed
重写slider组件
1 parent 59fbc09 commit 298220c

14 files changed

+2037
-519
lines changed

GaiaXiOS/GaiaXiOS.xcodeproj/project.pbxproj

+42-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
2CECF30401B7B1202EFE178B /* libPods-GaiaXiOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 26E99510FB4BAB41B3A64E70 /* libPods-GaiaXiOSTests.a */; };
1111
8A962CCA282A9DD100335552 /* GXSliderNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A962CC8282A9DD100335552 /* GXSliderNode.h */; };
1212
8A962CCB282A9DD100335552 /* GXSliderNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A962CC9282A9DD100335552 /* GXSliderNode.m */; };
13+
8D10145C2D096BEC0034A175 /* GXPagerLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014542D096BEC0034A175 /* GXPagerLayout.m */; };
14+
8D10145D2D096BEC0034A175 /* GXSliderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014552D096BEC0034A175 /* GXSliderView.m */; };
15+
8D10145E2D096BEC0034A175 /* GXPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014562D096BEC0034A175 /* GXPageControl.m */; };
16+
8D10145F2D096BEC0034A175 /* GXPagerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014572D096BEC0034A175 /* GXPagerView.m */; };
17+
8D1014602D096BEC0034A175 /* GXPagerLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1014582D096BEC0034A175 /* GXPagerLayout.h */; };
18+
8D1014612D096BEC0034A175 /* GXSliderView.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1014592D096BEC0034A175 /* GXSliderView.h */; };
19+
8D1014622D096BEC0034A175 /* GXPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D10145A2D096BEC0034A175 /* GXPageControl.h */; };
20+
8D1014632D096BEC0034A175 /* GXPagerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D10145B2D096BEC0034A175 /* GXPagerView.h */; };
1321
8D1CBCE727560A5F00EC2B4D /* GXBizHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1CBCE527560A5F00EC2B4D /* GXBizHelper.h */; };
1422
8D1CBCE827560A5F00EC2B4D /* GXBizHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1CBCE627560A5F00EC2B4D /* GXBizHelper.m */; };
1523
8D1CBCED275770F700EC2B4D /* GXEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1CBCEB275770F700EC2B4D /* GXEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -210,6 +218,14 @@
210218
8A962CC8282A9DD100335552 /* GXSliderNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXSliderNode.h; sourceTree = "<group>"; };
211219
8A962CC9282A9DD100335552 /* GXSliderNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXSliderNode.m; sourceTree = "<group>"; };
212220
8CF100DA07FB9596328219B4 /* Pods-GaiaXiOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GaiaXiOSTests.debug.xcconfig"; path = "Target Support Files/Pods-GaiaXiOSTests/Pods-GaiaXiOSTests.debug.xcconfig"; sourceTree = "<group>"; };
221+
8D1014542D096BEC0034A175 /* GXPagerLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXPagerLayout.m; sourceTree = "<group>"; };
222+
8D1014552D096BEC0034A175 /* GXSliderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXSliderView.m; sourceTree = "<group>"; };
223+
8D1014562D096BEC0034A175 /* GXPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXPageControl.m; sourceTree = "<group>"; };
224+
8D1014572D096BEC0034A175 /* GXPagerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXPagerView.m; sourceTree = "<group>"; };
225+
8D1014582D096BEC0034A175 /* GXPagerLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXPagerLayout.h; sourceTree = "<group>"; };
226+
8D1014592D096BEC0034A175 /* GXSliderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXSliderView.h; sourceTree = "<group>"; };
227+
8D10145A2D096BEC0034A175 /* GXPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXPageControl.h; sourceTree = "<group>"; };
228+
8D10145B2D096BEC0034A175 /* GXPagerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXPagerView.h; sourceTree = "<group>"; };
213229
8D1CBCE527560A5F00EC2B4D /* GXBizHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GXBizHelper.h; sourceTree = "<group>"; };
214230
8D1CBCE627560A5F00EC2B4D /* GXBizHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GXBizHelper.m; sourceTree = "<group>"; };
215231
8D1CBCEB275770F700EC2B4D /* GXEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GXEvent.h; sourceTree = "<group>"; };
@@ -419,6 +435,21 @@
419435
/* End PBXFrameworksBuildPhase section */
420436

421437
/* Begin PBXGroup section */
438+
8D1014532D096BEC0034A175 /* Slider */ = {
439+
isa = PBXGroup;
440+
children = (
441+
8D10145A2D096BEC0034A175 /* GXPageControl.h */,
442+
8D1014562D096BEC0034A175 /* GXPageControl.m */,
443+
8D1014582D096BEC0034A175 /* GXPagerLayout.h */,
444+
8D1014542D096BEC0034A175 /* GXPagerLayout.m */,
445+
8D10145B2D096BEC0034A175 /* GXPagerView.h */,
446+
8D1014572D096BEC0034A175 /* GXPagerView.m */,
447+
8D1014592D096BEC0034A175 /* GXSliderView.h */,
448+
8D1014552D096BEC0034A175 /* GXSliderView.m */,
449+
);
450+
path = Slider;
451+
sourceTree = "<group>";
452+
};
422453
8D1CBD1C2758AA4500EC2B4D /* GaiaXiOSTests */ = {
423454
isa = PBXGroup;
424455
children = (
@@ -785,8 +816,6 @@
785816
8DFEC2D427351928001F3B74 /* Node */ = {
786817
isa = PBXGroup;
787818
children = (
788-
8A962CC8282A9DD100335552 /* GXSliderNode.h */,
789-
8A962CC9282A9DD100335552 /* GXSliderNode.m */,
790819
8DFEC2EC27351BB6001F3B74 /* GXBaseNode.h */,
791820
8DFEC2ED27351BB6001F3B74 /* GXBaseNode.m */,
792821
8D9FC9CA273A21F600912EE6 /* GXViewNode.h */,
@@ -801,6 +830,8 @@
801830
8D9FC9DF273A224900912EE6 /* GXIconFontNode.m */,
802831
8D9FC9D2273A221A00912EE6 /* GXGridNode.h */,
803832
8D9FC9D3273A221A00912EE6 /* GXGridNode.m */,
833+
8A962CC8282A9DD100335552 /* GXSliderNode.h */,
834+
8A962CC9282A9DD100335552 /* GXSliderNode.m */,
804835
8D9FC9D6273A222B00912EE6 /* GXScrollNode.h */,
805836
8D9FC9D7273A222B00912EE6 /* GXScrollNode.m */,
806837
8D9FC9DA273A223A00912EE6 /* GXCustomNode.h */,
@@ -845,6 +876,7 @@
845876
8DFEC2E327351990001F3B74 /* Container */ = {
846877
isa = PBXGroup;
847878
children = (
879+
8D1014532D096BEC0034A175 /* Slider */,
848880
8DFEC2E827351A03001F3B74 /* GXScrollView.h */,
849881
8DFEC2E927351A03001F3B74 /* GXScrollView.m */,
850882
8DFF84E6273D183F0014C0DA /* GXRootView.h */,
@@ -950,12 +982,14 @@
950982
8DFEC25F2734DC08001F3B74 /* GXCommonDef.h in Headers */,
951983
8DFEC2612734DC19001F3B74 /* GXFunctionDef.h in Headers */,
952984
8DFEC2542734DB27001F3B74 /* GXUtils.h in Headers */,
985+
8D1014612D096BEC0034A175 /* GXSliderView.h in Headers */,
953986
8DFEC2742734DDC8001F3B74 /* NSArray+GX.h in Headers */,
954987
8DFEC2702734DDBE001F3B74 /* NSDictionary+GX.h in Headers */,
955988
8DE5E3A32745FD9400C9FA02 /* GXExpression.h in Headers */,
956989
8DE5E3862743A3F800C9FA02 /* GXRegisterCenter.h in Headers */,
957990
8DE14A18288E338100FCF226 /* GXProgressNode.h in Headers */,
958991
8A962CCA282A9DD100335552 /* GXSliderNode.h in Headers */,
992+
8D1014602D096BEC0034A175 /* GXPagerLayout.h in Headers */,
959993
8DB521692759C7C900EB8126 /* GXTrack.h in Headers */,
960994
8D1CBCED275770F700EC2B4D /* GXEvent.h in Headers */,
961995
8DB521652759C6A300EB8126 /* GXData.h in Headers */,
@@ -980,6 +1014,7 @@
9801014
8DE5E3962744DAA200C9FA02 /* GXUIHelper.h in Headers */,
9811015
8DE5E38227439BE900C9FA02 /* GXTemplateLoader.h in Headers */,
9821016
8DFEC2BF27350BBA001F3B74 /* libstretch.h in Headers */,
1017+
8D1014632D096BEC0034A175 /* GXPagerView.h in Headers */,
9831018
8DFEC2E6273519EE001F3B74 /* GXGridView.h in Headers */,
9841019
8DFF84E8273D183F0014C0DA /* GXRootView.h in Headers */,
9851020
8D9FC9E8273A227800912EE6 /* GXRootViewNode.h in Headers */,
@@ -995,6 +1030,7 @@
9951030
8DFEC2CA27350E26001F3B74 /* GXStretch.h in Headers */,
9961031
8D9FC9DC273A223A00912EE6 /* GXCustomNode.h in Headers */,
9971032
8DE5E3772743820A00C9FA02 /* GXTemplateParser.h in Headers */,
1033+
8D1014622D096BEC0034A175 /* GXPageControl.h in Headers */,
9981034
8DB60A1927F4764E0038BE13 /* GXValue.h in Headers */,
9991035
8DE14A1C288E339300FCF226 /* GXProgressView.h in Headers */,
10001036
8D9FC9CC273A21F600912EE6 /* GXViewNode.h in Headers */,
@@ -1242,6 +1278,7 @@
12421278
BD42E33529A4A4B200F3404E /* GXEventManager.m in Sources */,
12431279
8DFEC2652734DC56001F3B74 /* GXCssItem.m in Sources */,
12441280
8DFF84E9273D183F0014C0DA /* GXRootView.m in Sources */,
1281+
8D10145F2D096BEC0034A175 /* GXPagerView.m in Sources */,
12451282
8DFEC2712734DDBE001F3B74 /* NSDictionary+GX.m in Sources */,
12461283
8D9FC9E5273A225A00912EE6 /* GXRichTextNode.m in Sources */,
12471284
8DFF84F1273E60A80014C0DA /* GXTemplateManager.m in Sources */,
@@ -1263,6 +1300,7 @@
12631300
BD42E32F29A4A49F00F3404E /* GXJSDelegateImplManager.m in Sources */,
12641301
8DE5E38F2744B20200C9FA02 /* GXNodeHelper.m in Sources */,
12651302
8DE14A19288E338100FCF226 /* GXProgressNode.m in Sources */,
1303+
8D10145E2D096BEC0034A175 /* GXPageControl.m in Sources */,
12661304
8DE5E3A82746794300C9FA02 /* GXImageNode.m in Sources */,
12671305
8DE5E3B52747AF9600C9FA02 /* GXRichText.m in Sources */,
12681306
8D1D6300274F360600B94B1E /* GXDataManager.m in Sources */,
@@ -1278,6 +1316,7 @@
12781316
8DEEFED5276880F4008C73A5 /* GXCacheCenter.m in Sources */,
12791317
8DB5216A2759C7C900EB8126 /* GXTrack.m in Sources */,
12801318
8D1CBCEE275770F700EC2B4D /* GXEvent.m in Sources */,
1319+
8D10145C2D096BEC0034A175 /* GXPagerLayout.m in Sources */,
12811320
8DB521662759C6A300EB8126 /* GXData.m in Sources */,
12821321
8DCE3367283E451D00A42EF8 /* GXTemplateSource.m in Sources */,
12831322
8DFEC3042735319A001F3B74 /* GXBizContext.m in Sources */,
@@ -1295,6 +1334,7 @@
12951334
8DFEC2CB27350E26001F3B74 /* GXStretch.m in Sources */,
12961335
8DE5E37F27438A4E00C9FA02 /* GXTemplatePathHelper.m in Sources */,
12971336
8D9FC9E1273A224900912EE6 /* GXIconFontNode.m in Sources */,
1337+
8D10145D2D096BEC0034A175 /* GXSliderView.m in Sources */,
12981338
8DFEC2C327350E01001F3B74 /* GXLayout.m in Sources */,
12991339
);
13001340
runOnlyForDeploymentPostprocessing = 0;

GaiaXiOS/GaiaXiOS/Category/UIView+GX.h

+16
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,21 @@ NS_ASSUME_NONNULL_BEGIN
127127
@end
128128

129129

130+
@interface UIView (GXLayout)
131+
132+
@property (nonatomic) CGFloat gx_left; ///< Shortcut for frame.origin.x.
133+
@property (nonatomic) CGFloat gx_top; ///< Shortcut for frame.origin.y
134+
@property (nonatomic) CGFloat gx_right; ///< Shortcut for frame.origin.x + frame.size.width
135+
@property (nonatomic) CGFloat gx_bottom; ///< Shortcut for frame.origin.y + frame.size.height
136+
@property (nonatomic) CGFloat gx_width; ///< Shortcut for frame.size.width.
137+
@property (nonatomic) CGFloat gx_height; ///< Shortcut for frame.size.height.
138+
@property (nonatomic) CGFloat gx_centerX; ///< Shortcut for center.x
139+
@property (nonatomic) CGFloat gx_centerY; ///< Shortcut for center.y
140+
@property (nonatomic) CGPoint gx_origin; ///< Shortcut for frame.origin.
141+
@property (nonatomic) CGSize gx_size; ///< Shortcut for frame.size.
142+
143+
@end
144+
145+
130146

131147
NS_ASSUME_NONNULL_END

GaiaXiOS/GaiaXiOS/Category/UIView+GX.m

+137
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,140 @@ - (void)setBlurView:(UIVisualEffectView *)blurView{
385385

386386
@end
387387

388+
389+
#pragma mark - GaiaXTools
390+
391+
@implementation UIView (GaiaXTools)
392+
393+
- (UIViewController *)gx_viewController{
394+
for (UIView *view = self; view; view = view.superview) {
395+
UIResponder *nextResponder = [view nextResponder];
396+
if ([nextResponder isKindOfClass:[UIViewController class]]) {
397+
return (UIViewController *)nextResponder;
398+
}
399+
}
400+
return nil;
401+
}
402+
403+
- (void)gx_removeAllSubviews{
404+
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
405+
}
406+
407+
- (UIImage *)gx_snapshotImage{
408+
// UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0);
409+
// [self.layer renderInContext:UIGraphicsGetCurrentContext()];
410+
// UIImage *snap = UIGraphicsGetImageFromCurrentImageContext();
411+
// UIGraphicsEndImageContext();
412+
413+
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
414+
format.opaque = self.opaque;
415+
CGSize size = self.bounds.size;
416+
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:size format:format];
417+
UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
418+
[self.layer renderInContext:rendererContext.CGContext];
419+
}];
420+
return image;
421+
}
422+
423+
@end
424+
425+
426+
@implementation UIView (GXLayout)
427+
428+
- (CGFloat)gx_left {
429+
return self.frame.origin.x;
430+
}
431+
432+
- (void)setGx_left:(CGFloat)x {
433+
CGRect frame = self.frame;
434+
frame.origin.x = x;
435+
self.frame = frame;
436+
}
437+
438+
- (CGFloat)gx_top {
439+
return self.frame.origin.y;
440+
}
441+
442+
- (void)setGx_top:(CGFloat)y {
443+
CGRect frame = self.frame;
444+
frame.origin.y = y;
445+
self.frame = frame;
446+
}
447+
448+
- (CGFloat)gx_right {
449+
return self.frame.origin.x + self.frame.size.width;
450+
}
451+
452+
- (void)setGx_right:(CGFloat)right {
453+
CGRect frame = self.frame;
454+
frame.origin.x = right - frame.size.width;
455+
self.frame = frame;
456+
}
457+
458+
- (CGFloat)gx_bottom {
459+
return self.frame.origin.y + self.frame.size.height;
460+
}
461+
462+
- (void)setGx_bottom:(CGFloat)bottom {
463+
CGRect frame = self.frame;
464+
frame.origin.y = bottom - frame.size.height;
465+
self.frame = frame;
466+
}
467+
468+
- (CGFloat)gx_width {
469+
return self.frame.size.width;
470+
}
471+
472+
- (void)setGx_width:(CGFloat)width {
473+
CGRect frame = self.frame;
474+
frame.size.width = width;
475+
self.frame = frame;
476+
}
477+
478+
- (CGFloat)gx_height {
479+
return self.frame.size.height;
480+
}
481+
482+
- (void)setGx_height:(CGFloat)height {
483+
CGRect frame = self.frame;
484+
frame.size.height = height;
485+
self.frame = frame;
486+
}
487+
488+
- (CGFloat)gx_centerX {
489+
return self.center.x;
490+
}
491+
492+
- (void)setGx_centerX:(CGFloat)centerX {
493+
self.center = CGPointMake(centerX, self.center.y);
494+
}
495+
496+
- (CGFloat)gx_centerY {
497+
return self.center.y;
498+
}
499+
500+
- (void)setGx_centerY:(CGFloat)centerY {
501+
self.center = CGPointMake(self.center.x, centerY);
502+
}
503+
504+
- (CGPoint)gx_origin {
505+
return self.frame.origin;
506+
}
507+
508+
- (void)setGx_origin:(CGPoint)origin {
509+
CGRect frame = self.frame;
510+
frame.origin = origin;
511+
self.frame = frame;
512+
}
513+
514+
- (CGSize)gx_size {
515+
return self.frame.size;
516+
}
517+
518+
- (void)setGx_size:(CGSize)size {
519+
CGRect frame = self.frame;
520+
frame.size = size;
521+
self.frame = frame;
522+
}
523+
524+
@end

GaiaXiOS/GaiaXiOS/Component/Node/GXScrollNode.m

+7-12
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ @interface GXScrollNode ()<UICollectionViewDelegate, UICollectionViewDataSource,
4747
//横向模式下坑位位置
4848
@property (nonatomic, strong) NSString *gravity;
4949
//坑位Size数组
50-
@property (nonatomic, strong) NSMutableArray *sizeValues;
50+
@property (nonatomic, strong) NSArray *sizeValues;
5151
//坑位的复用标识
5252
@property (nonatomic, strong) NSMutableArray *identifiers;
5353
//子坑位的subItems
@@ -311,6 +311,8 @@ - (GXTemplateItem *)templateItemWithIdentifier:(NSString *)identifier{
311311

312312
//计算itemSize
313313
- (void)calculateItemSize:(NSDictionary *)extend{
314+
NSMutableArray *tmpSizeValues = [NSMutableArray array];
315+
314316
CGFloat measureWidth = NAN;
315317
CGFloat measureHeight = NAN;
316318
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
@@ -323,7 +325,6 @@ - (void)calculateItemSize:(NSDictionary *)extend{
323325
//计算itemSize
324326
_containerHeight = 0.f;
325327
CGSize itemSize = CGSizeZero;
326-
[self.sizeValues removeAllObjects];
327328
for (int i = 0; i < self.items.count; i++) {
328329
//获取坑位类型
329330
NSString *identifier = [self identifierWithIndex:i];
@@ -350,9 +351,10 @@ - (void)calculateItemSize:(NSDictionary *)extend{
350351
_containerHeight = itemHeight;
351352
}
352353
//添加到数组中
353-
[self.sizeValues gx_addObject:[NSValue valueWithCGSize:itemSize]];
354+
[tmpSizeValues gx_addObject:[NSValue valueWithCGSize:itemSize]];
354355
}
355-
356+
357+
self.sizeValues = tmpSizeValues;
356358
}
357359

358360

@@ -416,7 +418,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
416418

417419
//数据绑定
418420
GXTemplateData *data = [self.items objectAtIndex:index];
419-
[TheGXTemplateEngine bindData:data onView:rootView];
421+
[TheGXTemplateEngine bindData:data onView:rootView];
420422

421423
return cell;
422424
}
@@ -588,13 +590,6 @@ - (NSMutableArray *)items{
588590
return _items;
589591
}
590592

591-
- (NSMutableArray *)sizeValues{
592-
if (!_sizeValues) {
593-
_sizeValues = [NSMutableArray array];
594-
}
595-
return _sizeValues;
596-
}
597-
598593
- (NSMutableArray *)identifiers{
599594
if (!_identifiers) {
600595
_identifiers = [NSMutableArray array];

GaiaXiOS/GaiaXiOS/Component/Node/GXSliderNode.h

-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
2222

2323
@interface GXSliderNode : GXBaseNode
2424

25-
//内边距
26-
@property (nonatomic) UIEdgeInsets contentInset;
27-
//坑位间距
28-
@property (nonatomic, assign) CGFloat itemSpacing;
29-
//滚动方法
30-
@property (nonatomic) UICollectionViewScrollDirection scrollDirection;
31-
3225
@end
3326

3427
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)