看源码学知识(不定期更新)

// MBProgressHUD.m(版本 0.9.1)里面MBBarProgressView类的drawRect:方法里:
if (isnan(angle)) angle = 0;

isnan()函数用来判断一个变量(比如上面的angle)是不是数字,如果不是数字,返回YES
(isnan = is not a number)

[TOC]忽略编译器警告


忽略编译器警告(使用了已废弃方法、创建未使用的变量等),例子:
-Wdeprecated表示已废弃

//  SVProgressHUD.m里的361行
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
    //此处是你写的iOS7以后已废弃的方法
    stringSize = [string sizeWithFont:self.stringLabel.font constrainedToSize:CGSizeMake(200.0f, 300.0f)];
#pragma clang diagnostic pop

说MJRefresh是垃圾的这位大神自己写了个挺简洁的下拉刷新控件PRRefreshControl

//正常状态下,下拉后箭头朝下
case PRRefreshControlStateNormal:
{
    [UIView animateWithDuration:.2f animations:^{
        self.arrowImageView.hidden = NO;
        self.arrowImageView.transform = CGAffineTransformIdentity;
    }];
    [self.activityIndicator stopAnimating];
    break;
}

这里要说的是self.arrowImageView.transform = CGAffineTransformIdentity这句话,关于CGAffineTransformIdentity,苹果文档注释如下:

struct CGAffineTransform {
  CGFloat a, b, c, d;
  CGFloat tx, ty;
};

/* The identity transform: [ 1 0 0 1 0 0 ]. */ 
const CGAffineTransform CGAffineTransformIdentity

/* Return the transform [ a b c d tx ty ]. */ 
CGAffineTransform CGAffineTransformMake(CGFloat a, CGFloat b,
  CGFloat c, CGFloat d, CGFloat tx, CGFloat ty)

/* Return a transform which translates by `(tx, ty)':
     t' = [ 1 0 0 1 tx ty ] */
 CGAffineTransform CGAffineTransformMakeTranslation(CGFloat tx,
  CGFloat ty)

[ 1 0 0 1 0 0 ]是个什么鬼呢?

再次复制这一段
struct CGAffineTransform {
  CGFloat a, b, c, d;
  CGFloat tx, ty;
};
在二维空间里,如果原始坐标是(X,Y, 1)的话
           |a  b  0 |
|X,Y, 1|  |c  d  0 | = [aX + cY + tx, bX + dY + ty, 1] ;
           |tx ty  1|    
乘以矩阵之后(X,Y, 1)→(aX + cY + tx, bX + dY + ty, 1)

那么[ 1 0 0 1 0 0 ](CGAffineTransformIdentity)就相当于做了如下变换
           |1  0  0 |
|X,Y, 1|  |0  1  0 | = [X, Y, 1] ;
           |0  0  1|  

所以self.arrowImageView.transform = CGAffineTransformIdentity;这句话的意思就相当于重置位置的作用
也有人说

每次变换前都要置位,不然你变换用的坐标系统不是屏幕坐标系统(即绝对坐标系统),而是上一次变换后的坐标系统

CGAffineTransformMakeCGAffineTransformMakeTranslation同理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值