bb-coder / BHBPopView

仿新浪微博客户端“加号”按钮弹出动画
MIT License
282 stars 77 forks source link

如果BHBItem添加过多(9个)的话,移除动画的时候会出现事件无法传递,报unexpected nil window in __dispatchPreprocessedEventFromEventQueue的问题 #12

Open SenorSamuel opened 7 years ago

SenorSamuel commented 7 years ago

移除动画时,BHBItem过多,completed的时候self.superview.superview== nil 以下是我的解决方法,请勿见笑


- (void)removeAnimation{
    [self.visableBtnArray enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        BHBCustomBtn * btn = obj;
        CGFloat x = btn.frame.origin.x;
        CGFloat y = btn.frame.origin.y;
        CGFloat width = btn.frame.size.width;
        CGFloat height = btn.frame.size.height;
        UIView *containerView = self.superview.superview;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((self.visableBtnArray.count - idx) * 0.03 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:.5 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:5 options:0 animations:^{
                btn.alpha = 0;
                btn.frame = CGRectMake(x, [UIScreen mainScreen].bounds.size.height - self.frame.origin.y + y, width, height);
            } completion:^(BOOL finished) {
                if ([btn isEqual:[self.visableBtnArray firstObject]]) {
//                    self.superview.superview.userInteractionEnabled = YES;
                    containerView.userInteractionEnabled = YES;(改成这行)
                }
            }];
        });

    }];

}
bb-coder commented 7 years ago

赞👍,你提个mr我和进去~