-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
                 }];

ただし、セルだけが画面外に移動します。その代わりに灰色のビューはありません。

欠けているステップはありますか?このコードの何が問題になっていますか?

例の動画はこちら

4

2 に答える 2

1

大きなエラーは、sideView何にも初期化していないことです。

試すUIView* sideview = [[UIView alloc] initWithFrame:swipedCell.frame];

于 2013-06-19T18:22:14.640 に答える
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);
    }];

お役に立てれば!

于 2013-06-19T18:21:43.143 に答える