iOS: setting Exclusive Touch to all buttons in a view

后端 未结 8 449
灰色年华
灰色年华 2021-01-03 16:17

My app has many buttons in a Window and I want to set Exclusive Touch all of them together. Do you have any suggestion about this? Thanks

8条回答
  •  抹茶落季
    2021-01-03 17:08

    There is a way to set exclusive touch to all buttons in your app, may be helpful.

    #import 
    
    static IMP gOringinalWillMoveToSuperview = nil;
    
    static id newMoveToSuperviewPlusSettingExclusiveTouch(id self,SEL selector,...)
    {
        va_list arg_list;
        va_start( arg_list,selector);
        gOringinalWillMoveToSuperview(self,selector,arg_list);
        [self setExclusiveTouch:YES];
        return nil;
    }
    
    -(void)addSettingExclusiveTouchToAllUIViewMethodWillMoveToSuperview
    {
        gOringinalWillMoveToSuperview = class_getMethodImplementation([UIButton class], @selector(willMoveToSuperview:));
        class_replaceMethod([UIButton class], @selector(willMoveToSuperview:), &newMoveToSuperviewPlusSettingExclusiveTouch, "v@:");
    }
    

    if you don't understand this, you can refer to this and this.

提交回复
热议问题