SDWebImage 涉及知识点位移枚举的操作解析

凡是涉及枚举传值时,不了解的就直接传入0 因为枚举有个约定,传入值若为0则不进行任何有关操作。如果要传递多个值则多个枚举值之间用或 | 连接 作为参数传递即可

新建工程,代码如下:

//
//  ViewController.m
//  位移枚举详解
//
//  Created by apple on 15/10/25.
//  Copyright (c) 2015年 LiuXun. All rights reserved.
//

#import "ViewController.h"

typedef enum {
    CZActionTypeTop = 1<< 0,
    CZActionTypeBottom = 1 << 1,
    CZActionTypeLeft = 1 << 2,
    CZActionTypeRight = 1 <<3,
}CZActionType;

@interface ViewController ()

@end

@implementation ViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    [self test:0];  // 注意:枚举有个约定 如果传值为0  则不做任何操作
    //    [self test:CZActionTypeTop];
    //    [self test:CZActionTypeBottom];
    //    [self test:CZActionTypeTop|CZActionTypeBottom | CZActionTypeLeft | CZActionTypeRight ];
}

-(void)test:(CZActionType) type
{
    NSLog(@"%d", type);
    if (type & CZActionTypeTop) {
        NSLog(@"上");
    }
    if (type & CZActionTypeBottom) {
        NSLog(@"下");
    }
    if (type & CZActionTypeLeft) {
        NSLog(@"左");
    }
    if (type & CZActionTypeRight) {
        NSLog(@"右");
    }
    
}

/**
 注意:
 按位与 '&'  操作规则,只要有0便为0
 按位或 '|' 操作规则,只要有1便为1
 */
@end
运行结果依次如下所示:






原理剖析如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值