This commit is contained in:
lianxiang
2018-10-09 09:02:59 +08:00
parent 431a19b043
commit dc1b1e330f
50 changed files with 880 additions and 255 deletions
+22
View File
@@ -0,0 +1,22 @@
//
// GiGaPageControl.h
// GIGA
//
// Created by lianxiang on 2018/10/8.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface GiGaPageControl : UIPageControl
{
UIImage *_defalutImage;
UIImage *_currentImage;
}
@end
NS_ASSUME_NONNULL_END
+50
View File
@@ -0,0 +1,50 @@
//
// GiGaPageControl.m
// GIGA
//
// Created by lianxiang on 2018/10/8.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GiGaPageControl.h"
@implementation GiGaPageControl
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_defalutImage = [UIImage imageNamed:@"pagecontrol_def"];
_currentImage = [UIImage imageNamed:@"pagecontrol_current"];
}
return self;
}
-(void)updateDots{
for (int i =0; i<self.subviews.count; i++) {
UIView *dot = [self.subviews objectAtIndex:i];
dot.backgroundColor = [UIColor clearColor];
UIImageView *imageview = [[UIImageView alloc] init];
if (i == self.currentPage) {
imageview.image = _currentImage;
imageview.frame = CGRectMake(0, 0, 26, 8);
}else{
imageview.image = _defalutImage;
imageview.frame = CGRectMake(0,0,8, 8);
}
for (UIView *subViews in dot.subviews) {
[subViews removeFromSuperview];
}
[dot addSubview:imageview];
}
}
-(void)setCurrentPage:(NSInteger)currentPage
{
[super setCurrentPage:currentPage];
[self updateDots];
}
@end
+22
View File
@@ -0,0 +1,22 @@
//
// LXPageControl.h
// GIGA
//
// Created by lianxiang on 2018/10/8.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface LXPageControl : UIView
@property (nonatomic, assign) NSInteger numberOfPages;
@property (nonatomic, assign) NSInteger currentPage;
@property (nonatomic, strong) UIColor *tintColor;
@property (nonatomic, strong) UIColor *currentTintColor;
@end
NS_ASSUME_NONNULL_END
+194
View File
@@ -0,0 +1,194 @@
//
// LXPageControl.m
// GIGA
//
// Created by lianxiang on 2018/10/8.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "LXPageControl.h"
#define pointWidth 5
#define pointInterval 8
@interface LXPageControl ()
@property (nonatomic, strong) NSMutableArray *pageArray;
@end
@implementation LXPageControl
{
BOOL _shouldSetColor;
BOOL _isInit;
BOOL _inAni; // 是否在动画中
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
_tintColor = [UIColor lightGrayColor];
_currentTintColor = [UIColor whiteColor];
_shouldSetColor = NO;
_isInit = YES;
_inAni = NO;
if (!self.currentPage) {
self.currentPage = 0;
}
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.pageArray.count == 0) return;
if (_shouldSetColor)
{
for (int i = 0; i < self.pageArray.count; i++)
{
UIView *view = self.pageArray[i];
view.backgroundColor = self.tintColor;
if (i == _currentPage)
{
view.backgroundColor = self.currentTintColor;
}
_shouldSetColor = NO;
}
}
if (_isInit)
{
CGFloat totalWidth = _numberOfPages * pointWidth + (_numberOfPages - 1) * pointInterval;
for (int i = 0; i < self.pageArray.count; i++)
{
UIView *view = self.pageArray[i];
CGFloat x = (self.frame.size.width - totalWidth) * 0.5f + (pointWidth + pointInterval) * i;
CGFloat y = (self.frame.size.height - pointWidth) * 0.5f;
CGFloat width = (i==_currentPage?(pointWidth + pointInterval):pointWidth);
CGFloat height = pointWidth;
if (i == _currentPage)
{
x = x - pointInterval * 0.5f;
}
view.frame = CGRectMake(x, y, width, height);
_isInit = NO;
}
}
}
#pragma mark -- setter
- (void)setNumberOfPages:(NSInteger)numberOfPages
{
_numberOfPages = numberOfPages;
if (self.pageArray.count > 0)
{
[self.pageArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
{
[(UIView *)obj removeFromSuperview];
}];
[self.pageArray removeAllObjects];
}
for (int i = 0; i < numberOfPages; i++)
{
UIView *indicatorView = [[UIView alloc] initWithFrame:CGRectZero];
indicatorView.layer.cornerRadius = pointWidth * 0.5f;
[self addSubview:indicatorView];
[self.pageArray addObject:indicatorView];
}
_shouldSetColor = YES;
[self setNeedsLayout];
}
- (void)setCurrentPage:(NSInteger)currentPage
{
if (self.pageArray.count == 0)
{
_currentPage = currentPage;
return;
}
if (_currentPage == currentPage) return;
if (_inAni) return;
// 向右
if (currentPage > _currentPage)
{
UIView *currentView = self.pageArray[_currentPage];
UIView *nextView = self.pageArray[currentPage];
[self bringSubviewToFront:currentView];
_inAni = YES;
[UIView animateWithDuration:0.3 animations:^{
CGRect newFrame = currentView.frame;
newFrame.size = CGSizeMake((pointInterval + pointWidth) * (currentPage - self->_currentPage + 1), newFrame.size.height);
currentView.frame = newFrame;
} completion:^(BOOL finished)
{
[self bringSubviewToFront:nextView];
currentView.backgroundColor = self.tintColor;
nextView.backgroundColor = self.currentTintColor;
CGRect cFrame = currentView.frame;
nextView.frame = cFrame;
cFrame.origin = CGPointMake(cFrame.origin.x + pointInterval * 0.5f, cFrame.origin.y);
cFrame.size = CGSizeMake(pointWidth, pointWidth);
currentView.frame = cFrame;
[UIView animateWithDuration:0.3 animations:^{
CGRect newFrame = nextView.frame;
newFrame.size = CGSizeMake(pointInterval + pointWidth, newFrame.size.height);
newFrame.origin = CGPointMake(newFrame.origin.x + (pointInterval + pointWidth) * (currentPage - self->_currentPage), newFrame.origin.y);
nextView.frame = newFrame;
} completion:^(BOOL finished)
{
self->_currentPage = currentPage;
self->_inAni = NO;
}];
}];
}
// 向左
else
{
UIView *currentView = self.pageArray[_currentPage];
UIView *nextView = self.pageArray[currentPage];
[self bringSubviewToFront:currentView];
_inAni = YES;
[UIView animateWithDuration:0.3 animations:^{
CGRect newFrame = currentView.frame;
newFrame.size = CGSizeMake((pointInterval + pointWidth) * (self->_currentPage - currentPage + 1), newFrame.size.height);
newFrame.origin = CGPointMake(newFrame.origin.x - (pointInterval + pointWidth) * (self->_currentPage - currentPage), newFrame.origin.y);
currentView.frame = newFrame;
} completion:^(BOOL finished)
{
[self bringSubviewToFront:nextView];
currentView.backgroundColor = self.tintColor;
nextView.backgroundColor = self.currentTintColor;
CGRect cFrame = currentView.frame;
nextView.frame = cFrame;
cFrame.origin = CGPointMake(cFrame.origin.x + pointInterval * 0.5f + (pointInterval + pointWidth) * (self->_currentPage - currentPage), cFrame.origin.y);
cFrame.size = CGSizeMake(pointWidth, pointWidth);
currentView.frame = cFrame;
[UIView animateWithDuration:0.3 animations:^{
CGRect newFrame = nextView.frame;
newFrame.size = CGSizeMake(pointInterval + pointWidth, newFrame.size.height);
nextView.frame = newFrame;
} completion:^(BOOL finished)
{
self->_currentPage = currentPage;
self->_inAni = NO;
}];
}];
}
}
- (NSMutableArray *)pageArray
{
if (!_pageArray)
{
_pageArray = [NSMutableArray array];
}
return _pageArray;
}
@end
@@ -18,6 +18,7 @@
@property (nonatomic) NSTimeInterval currentTimeinterval;
@property (nonatomic,strong) LXCountTimer *timer;
@property (nonatomic,strong) NSTimer *playTimer;
@property (nonatomic,strong) UIImageView *holderImageView;
@end
@@ -48,6 +49,11 @@
-(void)setUP{
self.backgroundColor = [UIColor clearColor];
self.holderImageView.frame = CGRectMake(self.frame.size.width/2 -self.frame.size.width/4 , self.frame.size.width/2 -self.frame.size.width/4,self.frame.size.width/2, self.frame.size.width/2);
self.holderImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:self.holderImageView];
_currentTimeinterval = 0;
_isMoving = NO;
self.countLabel.frame = CGRectMake(_lineWidth, self.frame.size.height /2 - 15 , self.frame.size.width - _lineWidth*2, 30);
@@ -90,7 +96,14 @@
}
return _countLabel;
}
//停止图片
- (UIImageView *)holderImageView{
if (!_holderImageView) {
_holderImageView = [[UIImageView alloc] init];
_holderImageView.image = [UIImage imageNamed:@"bg_on"];
}
return _holderImageView;
}
- (void)setLineWidth:(CGFloat)lineWidth{
CAShapeLayer *backgroundLayer = [self createRingLayerWithCenter:CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2) radius:CGRectGetWidth(self.bounds) / 2 - lineWidth / 2 lineWidth:lineWidth color:self.backColor];