zoukankan      html  css  js  c++  java
  • UIControl类控件统一管理

    static char OperationKey;

     

    +(NSString *)eventName:(UIControlEvents)event

    {

        switch (event) {

            case UIControlEventTouchDown:          return @"UIControlEventTouchDown";

            case UIControlEventTouchDownRepeat:    return @"UIControlEventTouchDownRepeat";

            case UIControlEventTouchDragInside:    return @"UIControlEventTouchDragInside";

            case UIControlEventTouchDragOutside:   return @"UIControlEventTouchDragOutside";

            case UIControlEventTouchDragEnter:     return @"UIControlEventTouchDragEnter";

            case UIControlEventTouchDragExit:      return @"UIControlEventTouchDragExit";

            case UIControlEventTouchUpInside:      return @"UIControlEventTouchUpInside";

            case UIControlEventTouchUpOutside:     return @"UIControlEventTouchUpOutside";

            case UIControlEventTouchCancel:        return @"UIControlEventTouchCancel";

            case UIControlEventValueChanged:       return @"UIControlEventValueChanged";

            case UIControlEventEditingDidBegin:    return @"UIControlEventEditingDidBegin";

            case UIControlEventEditingChanged:     return @"UIControlEventEditingChanged";

            case UIControlEventEditingDidEnd:      return @"UIControlEventEditingDidEnd";

            case UIControlEventEditingDidEndOnExit:return @"UIControlEventEditingDidEndOnExit";

            case UIControlEventAllTouchEvents:     return @"UIControlEventAllTouchEvents";

            case UIControlEventAllEditingEvents:   return @"UIControlEventAllEditingEvents";

            case UIControlEventApplicationReserved:return @"UIControlEventApplicationReserved";

            case UIControlEventSystemReserved:     return @"UIControlEventSystemReserved";

            case UIControlEventAllEvents:          return @"UIControlEventAllEvents";

            default:

                return @"description";

        }

        return @"description";

    }

     

    - (void)handleControlEvent:(UIControlEvents)event withBlock:(void(^)(id sender))block {

        

        NSString *methodName = [UIControl eventName:event];

        

        NSMutableDictionary *opreations = (NSMutableDictionary*)objc_getAssociatedObject(self, &OperationKey);

        

        if(opreations == nil)

        {

            opreations = [[NSMutableDictionary alloc] init];

            objc_setAssociatedObject(self, &OperationKey, opreations, OBJC_ASSOCIATION_RETAIN);

        }

        [opreations setObject:block forKey:methodName];

        

        [self addTarget:self action:NSSelectorFromString(methodName) forControlEvents:event];

        

    }

     

    - (void)removeHandlerForEvent:(UIControlEvents)event

    {

        

        NSString *methodName = [UIControl eventName:event];

        NSMutableDictionary *opreations = (NSMutableDictionary*)objc_getAssociatedObject(self, &OperationKey);

        

        if(opreations == nil)

        {

            opreations = [[NSMutableDictionary alloc] init];

            objc_setAssociatedObject(self, &OperationKey, opreations, OBJC_ASSOCIATION_RETAIN);

        }

        [opreations removeObjectForKey:methodName];

        [self removeTarget:self action:NSSelectorFromString(methodName) forControlEvents:event];

    }

  • 相关阅读:
    跳转网页
    在代码插入图像的位置
    图像宽度和高度
    添加图像
    指向同一网站中其中的页面的链接
    指向其他网站的链接
    嵌套列表
    定义
    LeetCode561 数组拆分 I
    LeetCode344 反转字符串
  • 原文地址:https://www.cnblogs.com/ranger-jlu/p/4021951.html
Copyright © 2011-2022 走看看