??
#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];
}
// 位移枚舉在傳入?yún)?shù)時(shí),是使用 或運(yùn)算 的方式,
/*
先或后與比對(duì)出結(jié)果
以第一個(gè)舉例:
LKActionTypeBottom 左移1位 0010
LKActionTypeRight 左移3位 1000
1.或操作為 1010 為10
2.然后在與操作匹配
1010 與 0010 為0010 2
1010 與 1000 為 1000 8
*/
//傳多個(gè)參數(shù) 3個(gè)
//| (或運(yùn)算符) 0|1 = 1 0|0 = 0 1|1 = 1 只要有1那么結(jié)果就是1
//& (與運(yùn)算符) 0&1 = 0 0&0 = 0 1&1 = 1 只要有0那么結(jié)果就是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);
}
}
/*
控制臺(tái)輸出:
10
bottom---2
right---8
----------------------------------------分割線
13
top---1
right---8
向左---4
*/