iOS - 自定义动画版下拉刷新 MJRefresh

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

前言:有些BUG 待修复

一、导入第三方 MJRefresh (略)

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

  1)MSUDIYHeader.h 中代码

        #import <MJRefresh/MJRefresh.h>

        @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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,594评论 25 708
  • 第一百章 赵媛的做法就像是一个小孩子讨糖吃一般,如果可以得到张浩的注意,似乎就像是吃了糖一样甜蜜,但是如果张浩不理...
    chief风阅读 533评论 0 3
  • 入学已经一个多月了,孩子们到底学会了什么,练就了哪些好习惯,今天考验大家的时候到了 因为这节课准备充分,孩子们学得...
    我是张老师阅读 571评论 0 7
  • 嗯,虽然不了解后台,但是这个还是要自己生成(证书为windows下Apach+tomcat 使用)。 安装Open...
    Keike阅读 1,926评论 0 1
  • 1.不要浪费时间质疑自己,你质疑自己的时候你在原地踏步,而别人已经走了很远。 2.不要花时间去让别人喜欢你,因为喜...
    长亭微雨阅读 256评论 0 0

友情链接更多精彩内容