123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- //
- // FKRefreshTopView.m
- // FKRefreshControl
- //
- // Created by jack on 15/12/3.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #define RefreshCircleLineW 1.0f
- #define RefreshAnimMargin 30.f
- #define RefreshNoStrokeBottom 25.0f // 下拉缓存区
- #define RefreshRotationDuration 0.7f
- @interface FKAnimView : UIView
- @property (nonatomic, assign) CGFloat process;
- @end
- @implementation FKAnimView
- - (void)drawRect:(CGRect)rect{
-
- [super drawRect:rect];
-
- CGFloat areaMargin = RefreshAnimMargin + RefreshCircleLineW;
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- CGContextSetStrokeColorWithColor(context, UIColorFromRGB(0x444444).CGColor);
- CGContextSetLineWidth(context, RefreshCircleLineW);
-
- CGPoint center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
- CGContextAddArc(context, center.x, center.y, areaMargin / 2.0f - RefreshCircleLineW + 1, - M_PI_2, self.process * 2 * M_PI - M_PI_2, NO);
- CGContextDrawPath(context, kCGPathStroke);
-
- }
- @end
- #import "FKRefreshTopView.h"
- #define FKRefreshTopMargin 65.0f
- static NSInteger const MaxGifImageCount = 32;
- @interface FKRefreshTopView ()
- @property (nonatomic, strong) UIView *containerView;
- @property (nonatomic, strong) CAShapeLayer *circleLayer;
- @property (nonatomic, strong) CAShapeLayer *bgLayer;
- @property (nonatomic, strong) UIView *coverView;
- @property (nonatomic, strong) FKAnimView *circleView;
- @property (nonatomic,strong)UIImageView * imageView;
- @property (nonatomic,strong)UIImageView * gifImgView;
- @end
- @implementation FKRefreshTopView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addSubview:self.imageView];
- [self addSubview:self.gifImgView];
- }
- return self;
- }
- #pragma mark - FKRefreshDelegate
- - (void)resetLayoutSubViews{
- // 重新布局
-
- CGFloat height = CGRectGetHeight(self.bounds);
- CGFloat width = CGRectGetWidth(self.bounds);
- if (!height || !width) return;
-
- self.imageView.bounds = CGRectMake(0, 0, 32, 32);
- self.imageView.center = CGPointMake(width / 2.0f, CGRectGetMaxY(self.bounds) - 28);
-
- self.gifImgView.center = self.imageView.center;
- self.gifImgView.bounds = self.imageView.bounds;
- }
- - (void)didDisengageRefreshWithOffsetY:(CGFloat)y{
- // CGFloat process = - (y + RefreshNoStrokeBottom) / (FKRefreshTopMargin - RefreshNoStrokeBottom);
- // if (process < 0) process = 0;
- // self.circleView.process = process;
-
- // [self.circleView setNeedsDisplay];
- }
- - (void)canEngageRefreshWithOffsetY:(CGFloat)y{
- // CGFloat process = - (y + RefreshNoStrokeBottom) / (FKRefreshTopMargin - RefreshNoStrokeBottom);
- // if (process < 0) process = 0;
- // self.circleView.process = process;
- //
- // [self.circleView setNeedsDisplay];
- }
- - (void)startRefreshing{
- self.imageView.hidden = TRUE;
-
- self.gifImgView.hidden = FALSE;
- self.gifImgView.animationRepeatCount = 0;
- [self.gifImgView startAnimating];
- }
- - (void)finishRefreshing{
- self.imageView.hidden = FALSE;
-
- self.gifImgView.hidden = TRUE;
- [self.gifImgView stopAnimating];
- }
- #pragma mark - property
- - (UIImageView *)imageView{
- if (_imageView == nil) {
- _imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"imageBg"]];
- }
- return _imageView;
- }
- - (UIImageView *)gifImgView {
- if (!_gifImgView) {
- _gifImgView = [[UIImageView alloc] init];
-
- UIImage *image = nil;
- NSMutableArray *array = [NSMutableArray array];
- for (int idx = 1 ; idx <= MaxGifImageCount; idx++) {
- image = [UIImage imageNamed:[NSString stringWithFormat:@"pullimage%@", @(idx)]];
- if (image) {
- [array addObject:image];
- }
- }
-
- _gifImgView.animationImages = array;
- _gifImgView.animationDuration = 1.0f;
- }
- return _gifImgView;
- }
- - (FKAnimView *)circleView {
- if (_circleView == nil) {
- _circleView = [[FKAnimView alloc]init];
- _circleView.backgroundColor = [UIColor clearColor];
- _circleView.contentMode = UIViewContentModeRedraw;
- }
- return _circleView;
- }
- @end
|