从任何触摸点重新排序UITableViewCell(Xamarin)

时间:2015-08-08 13:15:05

标签: ios xamarin mono

我试试这个样本 http://b2cloud.com.au/tutorial/reordering-a-uitableviewcell-from-any-touch-point/ 但是对于xamarin这不起作用! 这是我的代码

public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
    {
        if(item.Description.Contains("UITableViewCellReorderControl"))
        {

                UIView resizedGripView = new UIView(new CGRect(0,0,item.Frame.X,item.Bounds.Height));
                resizedGripView.AddSubview(item);
                cell.AddSubview(resizedGripView);

                CGSize sizeDifference = new CGSize(resizedGripView.Frame.Size.Width - item.Frame.Size.Width,
                    resizedGripView.Frame.Size.Height - item.Frame.Size.Height);

                CGSize transformRatio = new CGSize(resizedGripView.Frame.Size.Width / item.Frame.Size.Width,
                    item.Frame.Size.Height / item.Frame.Size.Height);

                CGAffineTransform transform = CGAffineTransform.MakeIdentity();

                transform = CGAffineTransform.Scale(transform, transformRatio.Width, transformRatio.Height);
                nfloat two = new nfloat (2.0);
                nfloat df = -sizeDifference.Width / two;
                nfloat dff = -sizeDifference.Height / two;
                transform = CGAffineTransform.Translate(transform, df,dff);
                resizedGripView.BackgroundColor = UIColor.FromRGBA (17, 176, 13, 50);
                item.BackgroundColor = UIColor.Red;
                resizedGripView.Transform = transform;


    }

任何人哈尔普!

1 个答案:

答案 0 :(得分:0)

解决:

foreach (var item in cell.Subviews) {
                Console.WriteLine (item);
                if (item.Description.Contains ("UITableViewCellReorderControl")) {

                    UIView resizedGripView = new UIView(new CGRect(0,0,item.Frame.GetMaxX(),item.Frame.GetMaxY()));
                    resizedGripView.AddSubview(item);
                    cell.AddSubview(resizedGripView);

                    CGSize sizeDifference = new CGSize(resizedGripView.Frame.Size.Width - item.Frame.Size.Width,
                        resizedGripView.Frame.Size.Height - item.Frame.Size.Height);

                    CGSize transformRatio = new CGSize(resizedGripView.Frame.Size.Width / item.Frame.Size.Width,
                        item.Frame.Size.Height / item.Frame.Size.Height);

                    CGAffineTransform transform = CGAffineTransform.MakeIdentity();

                    transform = CGAffineTransform.Scale(transform, transformRatio.Width, transformRatio.Height);
                    nfloat two = new nfloat (2.0);
                    nfloat df = -sizeDifference.Width / two;
                    nfloat dff = -sizeDifference.Height / two;
                    transform = CGAffineTransform.Translate(transform, df,dff);

                    resizedGripView.Transform = transform;
                    item.Subviews [0].RemoveFromSuperview ();

                }
            }

我忘了GetMaxX& GetMaxY方法。这是工作!