2013-06-19 5 views
-1

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

CGPoint location = [gesture locationInView:tableView]; 
NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location]; 
UITableViewCell *swipedCell = [tableView cellForRowAtIndexPath:swipedIndexPath]; 

//code to create view 
UIView *sideView; 
sideView.backgroundColor = [UIColor lightGrayColor]; 
//set the side view frame to the same as the cell 
sideView.frame = swipedCell.frame; 
//add it to the tableview 
[tableView addSubview:sideView]; 

[UIView animateWithDuration:1 
       animations:^{ 
        sideView.frame = CGRectMake(0, swipedCell.frame.origin.y, swipedCell.frame.size.width, swipedCell.frame.size.height); 
        // While simultaneously moving the cell's frame offscreen 

        // The net effect is that the side swipe view is pushing the cell offscreen 
        swipedCell.frame = CGRectMake(swipedCell.frame.size.width, swipedCell.frame.origin.y, swipedCell.frame.size.width, swipedCell.frame.size.height); //move cell off 
       }]; 

Однако только ячейка перемещается с экрана. В его месте нет серого вида.

Есть ли уступ, который мне не хватает? Что не так с этим кодом?

Видео примера here

ответ

1

Большая ошибка в том, что вы не инициализируете sideView ни к чему.

Попробуйте UIView* sideview = [[UIView alloc] initWithFrame:swipedCell.frame];

+0

я должен был сделать UIView * вид = [[UIView Alloc] инициализации]; потому что я не хотел устанавливать кадр, пока анимация не произошла. Но это исправило мою проблему. –

+0

Получил меня на верном пути хотя бы. –

+0

Нет проблем. Иногда просто берет второй набор глаз, чтобы заметить глупые проблемы, как только вы слишком долго смотрели на что-то. – Idles

0

Это не звучит как хорошая идея, чтобы добавить представление вместо ячейки так же, как это. Вам придется иметь дело с прокруткой, редактированием табличного вида и другими вещами, которые UITableView позаботится о вас. Поэтому вместо того, попробуйте добавить Sideview как подвид из swipedCell.contentView, а затем делают эту анимацию вместо:

[UIView animateWithDuration:1 animations:^{ 
    sideView.frame = CGRectMake(0, swipedCell.frame.origin.y, swipedCell.frame.size.width, swipedCell.frame.size.height); 
    //This moves all the subviews except for the sideView off the screen 
    for (UIView *subview in swipedCell.contentView.subviews) 
     if (![subview isEqual:sideView]) 
      subview.frame = CGRectOffset(subview.frame, swipedCell.frame.size.width, 0.0); 
    }]; 

Надеется, что это помогает!

Смежные вопросы