0

このチュートリアルを使用して、並べ替えボタンがセル全体をカバーするようにしようとしています。セルがビューから消えるまでうまく機能します。セルに戻ると、並べ替えボタンがかなり移動しています。

この図では、赤は再注文ボタンを表しています。 写真

チュートリアルで使用するコードは次のとおりです。

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //  Grip customization code goes in here...
    for(UIView* view in cell.subviews)
    {
         if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
        {
                UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
            [resizedGripView addSubview:view];
            [cell addSubview:resizedGripView];
            [resizedGripView release];

            CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - view.frame.size.width, resizedGripView.frame.size.height - view.frame.size.height);
            CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width / view.frame.size.width, resizedGripView.frame.size.height / view.frame.size.height);

            //  Original transform
            CGAffineTransform transform = CGAffineTransformIdentity;

            //  Scale custom view so grip will fill entire cell
            transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height);

            //  Move custom view so the grip's top left aligns with the cell's top left 
            transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2.0, -sizeDifference.height / 2.0);

            [resizedGripView setTransform:transform];

            for(UIImageView* cellGrip in view.subviews)
            {
                if([cellGrip isKindOfClass:[UIImageView class]])
                    [cellGrip setImage:nil];
            }
        }
    }
}

並べ替えコントロールが左に移動しないようにするにはどうすればよいですか? 変換を再度変換しようとしましたが、並べ替えコントロールが完全に画面から外れてしまいます。左に移動するコードの何が問題なのですか?どうすれば修正できますか?

4

1 に答える 1

0

やり方わかった!resizedGripView の初期フレームを格納するプロパティを viewController に追加する必要がありました。メソッドが呼び出されるたびに(セルが再び表示されるたびに)、並べ替えボタンが現在の位置から移動していたため、初期位置を保存する必要がありました。

UIView* resizedGripView = [[UIView alloc] init];
if (!initialFrame.size.height)
   [resizedGripView setFrame: CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
else
   [resizedGripView setFrame: initialFrame];

if (!initialFrame.size.height)
   [self setInitialFrame: resizedGripView.frame];
于 2013-04-25T12:13:52.033 に答える