Перетащите проблему невидимой ячейки представления коллекции - PullRequest
0 голосов
/ 20 сентября 2018

Обновленное описание

Пожалуйста, найдите изображение здесь.

здесь я использовал два сборных вида. Один для вопроса и второй для варианта иЯ хочу заполнить пробел с помощью перетаскивания.

, но возникает проблема, связанная с пользовательским интерфейсом, когда я перетаскиваю опцию для заполнения и когда она выходит за пределы представления коллекции, она отображаетсяпроблема, как на картинке ниже.

Я пытался удалить невидимую ячейку, но она не работает.

Я знаю, что есть проблема, связанная с scroll и clipToBound, но когда я даю clipToBound = true, я не могучтобы увидеть мой перетаскиваемый параметр после представления коллекции, и во-вторых, когда я даю clipToBound = no, есть проблема показа, как в изображении, которое находится в ссылке ниже

, так что теперь я хочу знать, что я буду делать каксогласно моему требованию, чтобы полностью заполнить и еще одна вещь, параметры являются динамическими приходят с сервера.Пожалуйста, дайте мне ответ и спасибо заранее

 - (void)labelDragged:(UIPanGestureRecognizer *)gesture
    {

        //for clip to bound
        collectionViewAnswers.clipsToBounds = true;



        UILabel *label = (UILabel *)gesture.view;
        CGRect labelframe = [label convertRect:label.bounds toView:self.view];


        if (labelframe.origin.y <= 218.000000) {
            collectionViewAnswers.clipsToBounds = NO;
            [self removeNaughtyLingeringCells];
        }

        if (gesture.state == UIGestureRecognizerStateEnded) {

            NSArray *ary = collectionViewQuestion.visibleCells;

            for (DragDropCollectionViewCell *cell in ary)
            {
                CGRect cellFrame = [cell convertRect:cell.bounds toView:self.view];

                if (CGRectIntersectsRect(labelframe, cellFrame))
                {

                    // NSLog(@"%ld",(long)cell.tag);

                    NSIndexPath *indexPath = [collectionViewQuestion indexPathForCell:cell];

                    NSMutableDictionary *dict = [arrQueAnsData objectAtIndex:APP_DELEGATE.nextPreviousCount];
                    NSMutableArray *arrinnner =  [[dict valueForKey:@"questionToShow"] mutableCopy];

                    NSMutableArray *arrSections = [[[dict valueForKey:@"questionToShow"]objectAtIndex:indexPath.section] mutableCopy];

                    NSMutableDictionary *dictInner = [arrSections objectAtIndex:indexPath.row];

                    if ([[dictInner valueForKey:@"questionTest"] isEqualToString:@"blank"] || [[dict valueForKey:@"questionTest"] isEqualToString:@"blankdot"])
                    {
                        NSInteger previousState = 0;
                        BOOL isvalid = FALSE;
                        if ([[dictInner valueForKey:@"selectedText"] length] !=0)
                        {
                            isvalid = TRUE;
                            previousState = [[dictInner valueForKey:@"isSelected"] integerValue];
                           // NSLog(@"%ld",(long)previousState);
                        }

                        [dictInner setObject:[NSString stringWithFormat:@"%ld",(long)label.tag] forKey:@"isSelected"];
                        [dictInner setObject:label.text forKey:@"selectedText"];

                        if ([[dict valueForKey:@"questionTest"] isEqualToString:@"blankdot"])
                        {
                            [dictInner setObject:[NSString stringWithFormat:@"%@.",label.text] forKey:@"selectedText"];
                        }

                        [arrSections replaceObjectAtIndex:indexPath.row withObject:dictInner];

                        [arrinnner replaceObjectAtIndex:indexPath.section withObject:arrSections];
                        [dict setObject:arrinnner forKey:@"questionToShow"];


                        NSMutableArray *arrinnnerAnswer =  [[dict valueForKey:@"answerToShow"] mutableCopy];

                        [arrinnnerAnswer removeObjectAtIndex:label.tag];



                        [dict setObject:arrinnnerAnswer forKey:@"answerToShow"];

                        [dict setObject:@"1" forKey:@"answer_given_or_not"];

                        [arrQueAnsData replaceObjectAtIndex:APP_DELEGATE.nextPreviousCount withObject:dict];



                        //[self setArrayObjectRandom];

                        label.hidden = YES;
                        label.userInteractionEnabled = NO;
                        break;
                    }
                }
            }

         //   NSLog(@"%@",arrQueAnsData);

            [collectionViewQuestion reloadData];
            [collectionViewAnswers reloadData];
        }
        else {

            CGPoint translation = [gesture translationInView:label];

            // move label
            label.center = CGPointMake(label.center.x + translation.x,
                                       label.center.y + translation.y);

            // reset translation
            [gesture setTranslation:CGPointZero inView:label];
        }
    }

    - (void) removeNaughtyLingeringCells {

        // 1. Find the visible cells
        NSArray *visibleCells = collectionViewAnswers.visibleCells;
        //NSLog(@"We have %i visible cells", visibleCells.count);

        // 2. Find the visible rect of the collection view on screen now
        CGRect visibleRect;
        visibleRect.origin = collectionViewAnswers.contentOffset;
        visibleRect.size = collectionViewAnswers.bounds.size;
        //NSLog(@"Rect %@", NSStringFromCGRect(visibleRect));

        int i=0;
        // 3. Find the subviews that shouldn't be there and remove them
        //NSLog(@"We have %i subviews", self.collectionView.subviews.count);
        for (UIView *aView in [collectionViewAnswers subviews]) {
            if ([aView isKindOfClass:UICollectionViewCell.class]) {
                CGPoint origin = aView.frame.origin;
                if(CGRectContainsPoint(visibleRect, origin)) {
                    if (![visibleCells containsObject:aView]) {
                        [aView removeFromSuperview];
                        aView.backgroundColor = [UIColor clearColor];

                        i++;
                        NSLog(@"-----<>%d",i);
                    }
                }
            }
        }
        //NSLog(@"%i views shouldn't be there", viewsShouldntBeThere.count);

        // 4. Refresh the collection view display
        [collectionViewAnswers setNeedsDisplay];
    }

    - (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
        if (!decelerate) {
            [self removeNaughtyLingeringCells];
        }
    }

    - (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
        [self removeNaughtyLingeringCells];
    }
...