Xamarin iOS-从自定义UITableViewCell类引用UIView的问题

Xamarin iOS-从自定义UITableViewCell类引用UIView的问题,ios,uitableview,xamarin,xamarin.ios,Ios,Uitableview,Xamarin,Xamarin.ios,我想在单元格中点击视图时创建一个简单的动画。点击此视图时,我想将其颜色更改为蓝色,并将其滑动到屏幕右侧 我面临两个挑战: 我如何引用被点击的确切视图 目前,不止一个视图被更改为蓝色,甚至不是被点击的视图,而我只希望点击的视图会更改 视图未滑动/隐藏。这是一个信息覆盖。我想通过将它向右滑动来隐藏它,如果它被拉出(为了隐藏信息),然后将它向后滑动到左侧,当用户再次点击它时显示信息。基本上是打开/关闭动画 任何帮助都将不胜感激 public override UITableViewCell Get

我想在单元格中点击视图时创建一个简单的动画。点击此视图时,我想将其颜色更改为蓝色,并将其滑动到屏幕右侧

我面临两个挑战:

  • 我如何引用被点击的确切视图 目前,不止一个视图被更改为蓝色,甚至不是被点击的视图,而我只希望点击的视图会更改

  • 视图未滑动/隐藏。这是一个信息覆盖。我想通过将它向右滑动来隐藏它,如果它被拉出(为了隐藏信息),然后将它向后滑动到左侧,当用户再次点击它时显示信息。基本上是打开/关闭动画
  • 任何帮助都将不胜感激

      public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
        {
            cell = tableView.DequeueReusableCell (CustomCell.Key) as CustomCell;
    
            if (cell == null) {
    
                cell = new CustomCell ();
    
            }
    
            try
            {
                cell.cellImageView.Image = TableItems[indexPath.Row];
    
                tapOnOverlay = new UITapGestureRecognizer(HideTheOverlay);
                cell.overlay.UserInteractionEnabled = true;
                cell.overlay.AddGestureRecognizer(tapOnOverlay);
    
        }
            catch (Exception imageException)
            {
                Console.Write(imageException.Message);
            }
    
            return cell;
        }
    
    
     public void HideTheOverlay()
        {
            try{
    
                UIView.Animate(2.0,()=> {
    
    // How do I get a reference to the exact view that was tapped on here??
    
    cell.overlay.Layer.BackgroundColor = UIColor.Blue.CGColor;
    
    // This does not move the view. Nothing happens here
    
    cell.overlay.Layer.Frame = new RectangleF(
                            new PointF((float)cell.overlay.Layer.Frame.Location.X + 200, 
                                (float)cell.overlay.Layer.Frame.Location.Y),
                            (SizeF)cell.overlay.Frame.Size);
    
    
                });
    
            }catch(Exception ex)
            {
                Console.Write(ex.Message + ex.StackTrace);
    
            }
    

    我找到了解决上述问题的办法

    我在
    HideOverlay
    函数中将
    uitappesturerecognizer
    作为参数传递,因此为了获得选中/点击的视图,我通过从手势识别器调用
    view
    属性来访问它。从那里,我可以通过访问视图的
    来设置视图的动画

    下面是我的打开/关闭动画的完整实现

    public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
        {
            CustomCell cell = tableView.DequeueReusableCell (CustomCell.Key) as CustomeCell;
    
            if (cell == null) {
    
                cell = new CustomCell ();
    
            }
                tapOnOverlay = new UITapGestureRecognizer(HideTheOverlay);
                cell.overlay.AddGestureRecognizer(tapOnOverlay);
                cell.overlay.UserInteractionEnabled = true;
    
           catch (Exception imageException)
            {
                Console.Write(imageException.Message);
            }
    
            return cell;
        }
    
    隐藏覆盖功能

         public void HideTheOverlay(UITapGestureRecognizer tap)
        {
            try{
    
                UIView.Animate(1.5,()=> {
    
                    float offsetXClose = (float)UIScreen.MainScreen.Bounds.Width - ((float)tap.View.Layer.Frame.Location.X + 20);
    
                    float offsetXOpen = (float)UIScreen.MainScreen.Bounds.Width - ((float)tap.View.Layer.Frame.Width);
    
    
                    float currentXPosition = (float)tap.View.Layer.Frame.Location.X;
    
                    float finalXPosition = currentXPosition + offsetXClose;
    
    
                    if(currentXPosition == finalXPosition) //Means the overlay is already closed. We should open it
                    {
    
                        //Open the overlay by moving it to the left
                        tap.View.Layer.Frame = new RectangleF(
                            new PointF((float)tap.View.Layer.Frame.Location.X - offsetXOpen, 
                                (float)tap.View.Layer.Frame.Location.Y),
                            (SizeF)tap.View.Frame.Size);
    
                    }else{
    
                        //Close the overlay, by moving it to the right
                        tap.View.Layer.Frame = new RectangleF(
                            new PointF((float)tap.View.Layer.Frame.Location.X + offsetXClose, 
                                (float)tap.View.Layer.Frame.Location.Y),
                            (SizeF)tap.View.Frame.Size);
                    }
    
    
                });
    
            }catch(Exception ex)
            {
                Console.Write(ex.Message + ex.StackTrace);
    
            }
    
        }
    

    不确定这是否是问题的根源,但您是否意识到如果重复使用该单元,您将以不止一个手势识别器结束?这是真的。我没有意识到这一点。我所要做的就是给自定义单元格中的视图设置动画。我如何使用最佳实践来实现这一目标?