Get the current first responder without using a private API

前端 未结 28 2260
夕颜
夕颜 2020-11-22 05:03

I submitted my app a little over a week ago and got the dreaded rejection email today. It tells me that my app cannot be accepted because I\'m using a non-public API; specif

28条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 05:53

    Code below work.

    - (id)ht_findFirstResponder
    {
        //ignore hit test fail view
        if (self.userInteractionEnabled == NO || self.alpha <= 0.01 || self.hidden == YES) {
            return nil;
        }
        if ([self isKindOfClass:[UIControl class]] && [(UIControl *)self isEnabled] == NO) {
            return nil;
        }
    
        //ignore bound out screen
        if (CGRectIntersectsRect(self.frame, [UIApplication sharedApplication].keyWindow.bounds) == NO) {
            return nil;
        }
    
        if ([self isFirstResponder]) {
            return self;
        }
    
        for (UIView *subView in self.subviews) {
            id result = [subView ht_findFirstResponder];
            if (result) {
                return result;
            }
        }
        return nil;
    }   
    

提交回复
热议问题