美文网首页
OC 位移枚举

OC 位移枚举

作者: 奋斗的郅博 | 来源:发表于2019-04-18 09:46 被阅读0次
🌃
#import "NewViewController.h"
typedef NS_OPTIONS(NSUInteger, LKActionType) {
    LKActionTypeTop  =    1 << 0, // 1  左移0位
    LKActionTypeBottom  =    1 << 1, // 2  左移1位
    LKActionTypeLeft  =    1 << 2, // 4 左移2位
    LKActionTypeRight  =    1 << 3, // 8 左移3位
};
@interface ViewController ()
@end

@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{

    [self actionType:LKActionTypeBottom | LKActionTypeRight];
    NSLog(@"----------------------------------------分割线");
    [self actionType:LKActionTypeTop | LKActionTypeLeft | LKActionTypeRight];
}

// 位移枚举在传入参数时,是使用 或运算 的方式,
/*
先或后与比对出结果
以第一个举例:
LKActionTypeBottom 左移1位 0010 
LKActionTypeRight     左移3位 1000 
1.或操作为 1010 为10
2.然后在与操作匹配
1010 与 0010 为0010   2
1010 与 1000 为 1000  8

 
 */
//传多个参数 3个
//| (或运算符)   0|1 = 1 0|0 = 0 1|1 = 1  只要有1那么结果就是1
//& (与运算符)   0&1 = 0 0&0 = 0 1&1 = 1  只要有0那么结果就是0
-(void) actionType:(LKActionType)type
{
    NSLog(@"%zd",type);
    
    if (type &  LKActionTypeTop) {
        NSLog(@"top---%zd",type & LKActionTypeTop);
    }
//    1010;
//    0010;
    
    if (type & LKActionTypeBottom) {
        NSLog(@"bottom---%zd",type &  LKActionTypeBottom);
    }
    
    if (type & LKActionTypeRight) {
        NSLog(@"right---%zd",type &  LKActionTypeRight);
    }
    
    if (type &  LKActionTypeLeft) {
        NSLog(@"left---%zd",type &  LKActionTypeLeft);
    }
    
    
}

/*
 控制台输出:
10
bottom---2
right---8
 
----------------------------------------分割线
 
13
top---1
right---8
向左---4
 */

相关文章

  • OC 位移枚举

  • 位移枚举

    位移枚举 一. OC中常见的三种枚举 C语言枚举 // C语言枚举 typedef enum : NSUInteg...

  • Swift使用OC位移枚举

    Swift使用OC的位移枚举的话可以像写数组一样例如

  • Swift&OC位移枚举区别

    1、Swift 位移枚举写法 2、ObjC位移枚举写法 相比之下ObjC更加简单明了。

  • 位移枚举

    位移枚举和普通枚举的区别位移枚举可以传递多个参数,普通的枚举只能传递单个参数 举个?在SDWebimage里有的地...

  • swift中定义位移枚举

    swift 是没有类似OC中多个位移枚举做集成。所以就需要定义一个OC的桥接文件来做这件事情。这里拿 NSKeyV...

  • 位移枚举

    位移枚举 C语言枚举定义 苹果创建枚举的定义方式

  • 位移枚举

    枚举的其中一种方式:位移枚举,直接上代码,看完基本就懂了 写一个方法: 在viewDidLoad方法中调用本方法:

  • 位移枚举

  • 位移枚举

    使用场景:同一次操作有多个选项,可以同时多选同时禁用摘取一段定义好的iOS代码 写一个方法,需要选择两种特性来实现...

网友评论

      本文标题:OC 位移枚举

      本文链接:https://www.haomeiwen.com/subject/wfxzwqtx.html