iOS进阶

2018-07-19  本文已影响0人  alex_zn

git 回顾

tableview 要点

UI事件传递响应

uiview -> layer(calayer,(contents->backing store)) -> backgoundcolor(层级关系)

总结: UIView 是提供显示内容,以及处理触等事件以及参与响应链,CAlayer负责显示视图内容等contents

主要有两个方法参与: hitTest(point:CGPoint,event:UIEvent) -> UIView; point(inside:CGPoint,event:UIEvent)->Bool;

点击屏幕 -> UIApplication -> UIWindow -> hitTest-> pointInsinde(倒序遍历子视图 hitTest) -> view

OC基础

分类

Runtime

数据结构

class = objc_class -> 继承objc_object

objc_object (isa指针 )

objc_class(Class superClass, cache_t cache, class_data_bits_t bits)

isa_t 是共用体结构(指针型isa,非指针型isa)

// objc_object数据结构
struct objc_object {
private:
    isa_t isa;
};
// isa共用体结构
union isa_t {
    isa_t() { }
    isa_t(uintptr_t value) : bits(value) { }

    Class cls;
    uintptr_t bits;

    struct {
        uintptr_t nonpointer        : 1;
        uintptr_t has_assoc         : 1;
        uintptr_t has_cxx_dtor      : 1;
        uintptr_t shiftcls          : 33; // MACH_VM_MAX_ADDRESS 
        uintptr_t magic             : 6;
        uintptr_t weakly_referenced : 1;
        uintptr_t deallocating      : 1;
        uintptr_t has_sidetable_rc  : 1;
        uintptr_t extra_rc          : 19;
    };
 }

// objcet_class 结构
struct objc_class : objc_object {
    // Class ISA;
    Class superclass;
    cache_t cache;             // formerly cache pointer and vtable hash查找
    class_data_bits_t bits;    // class_rw_t * plus custom rr/alloc flags
    class_rw_t *data() {
        return bits.data();
    }
    void setData(class_rw_t *newData) {
      bits.setData(newData);
    }
};

// 存放 实例方法,属性名
struct class_rw_t {
  uint32_t flags;
  uint32_t version;
  const class_ro_t *ro;         // 成员信息
  
  method_array_t methods;       //方法列表
  property_array_t properties;  //属性列表
  protocol_array_t protocols;   //协议列表
  
  Class firstSubclass;
  Class nextSiblingClass;
}

// 存放 成员变量信息
struct class_ro_t {
    uint32_t flags;
    uint32_t instanceStart;
    uint32_t instanceSize;
    
    const uint8_t * ivarLayout;
 
    const char * name;              // 类名
    method_list_t * baseMethodList;
    protocol_list_t * baseProtocols;
    const ivar_list_t * ivars;      //定义类的成员变量
 
    const uint8_t * weakIvarLayout;
    property_list_t *baseProperties;    //属性列表
 
    method_list_t *baseMethods() const {
        return baseMethodList;
    }
};


消息转发
image
上一篇 下一篇

猜你喜欢

热点阅读