博客> iOS - 自定义动画版下拉刷新 MJRefresh
iOS - 自定义动画版下拉刷新 MJRefresh
1小时前 评论:0 阅读:860 OS_JJ
ios MJRefresh 自定义下拉刷新

 A497C8CB-99BF-44A0-902B-3B19E54763E1.png

前言:有些BUG 待修复

一、导入第三方 MJRefresh (略)

二、自定义 DIY类文件 继承于 MJRefreshHeader

  1)MSUDIYHeader.h 中代码

        #import <MJRefresh>

        @interface MSUDIYHeader : MJRefreshHeader
        @property (nonatomic , strong) UIImageView *freshImaView;

        @end

2) MSUDIYHeader.m 中代码

        #import "MSUDIYHeader.h"
        #import "MSUPathTools.h"

        @interface MSUDIYHeader ()

        @end

        @implementation MSUDIYHeader

        - (void)prepare{
            [super prepare];

            self.mj_h = 30;

            self.freshImaView = [[UIImageView alloc] init];
            _freshImaView.contentMode = UIViewContentModeScaleAspectFit;
            // MSUPathTools 属于自定义封装文件,显示图片的 ,测试可以用 imageNamed
            _freshImaView.image = [MSUPathTools showImageWithContentOfFileByName:@"WechatIMG957"];
            [self addSubview:_freshImaView];

        //    self.arrowView.image = [MSUPathTools showImageWithContentOfFileByName:@"WechatIMG957"];

            //根据拖拽的情况自动切换透明度
        //    self.automaticallyChangeAlpha = YES;

        }

        - (void)placeSubviews{
            [super placeSubviews];

            CGFloat wid = [UIScreen mainScreen].bounds.size.width;
            self.freshImaView.frame = CGRectMake(wid*0.5-15, 5, 30, 20);

        }

        #pragma mark 监听scrollView的contentOffset改变
        - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
        {
            [super scrollViewContentOffsetDidChange:change];

        }

        #pragma mark 监听scrollView的contentSize改变
        - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
        {
            [super scrollViewContentSizeDidChange:change];

        }

        #pragma mark 监听scrollView的拖拽状态改变
        - (void)scrollViewPanStateDidChange:(NSDictionary *)change
        {
            [super scrollViewPanStateDidChange:change];

        }

        #pragma mark 监听控件的刷新状态
        - (void)setState:(MJRefreshState)state
        {
            MJRefreshCheckState;

            switch (state) {
                case MJRefreshStateIdle:
                {
                    self.freshImaView.transform = CGAffineTransformIdentity;
                }
                    break;
                case MJRefreshStatePulling:
                {

                }
                    break;
                case MJRefreshStateRefreshing:
                {

        //            [UIView animateWithDuration:0.01 animations:^{
        //                self.freshImaView.transform = CGAffineTransformMakeRotation(6.38);
        //            }];
                    CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
                    // 旋转速度 可以在此调整
                    anima.toValue = [NSNumber numberWithFloat:M_PI*12.0];
                    anima.duration = 8.5f;
                    anima.cumulative = YES;
                    anima.repeatCount = 1;
                    [_freshImaView.layer addAnimation:anima forKey:@"rotationAnimation"];

                }
                    break;
                case MJRefreshStateNoMoreData:
                {
                    self.freshImaView.transform = CGAffineTransformIdentity;

                }
                    break;
                default:
                    break;
            }
        }

        @end
收藏
0
sina weixin mail 回到顶部