2016-03-17 2 views
0

Я хотел бы создать простую анимацию, когда представление отображается в ячейке. Когда это представление используется, я хотел бы изменить его цвет на синий и слайд это справа от экрана.Xamarin iOS - проблема, связанная с UIView из пользовательского класса UITableViewCell

У меня есть две проблемы:

  1. Как ссылающихся точное представление, которое было повернутым?

В настоящее время более одного вида заменено на синий, даже на тот, который был использован, когда я ожидаю, что измененный вид изменится.

  1. Вид не помещается/скрывается. Это информационный оверлей. Я хотел бы спрятать его, сдвинув его вправо, если он вытянут (чтобы скрыть информацию), а затем сдвиньте его влево, чтобы отобразить информацию, когда пользователь снова на нее нажмет. В основном, открытая/закрытая анимация.

Любая помощь была бы принята с благодарностью.

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); 

     } 
+1

Не уверен, если это корень вашей проблемы, но вы понимаете, если ячейка Повторное использование закончится более чем одним повторителем жестов? – Gusman

+0

Это правда. Я этого не осознавал. Все, что я пытаюсь сделать, - это оживить представление, которое существует внутри пользовательской ячейки. Как мне это сделать, используя лучшие практики? – naffie

ответ

0

Я нашел решение моей проблемы выше.

Я прошел UITapGestureRecognizer в качестве параметра в моей HideOverlay функции и, таким образом, чтобы получить выбранный/повернутым вид, я к нему доступ, вызвав View свойство из жест распознаватель. Оттуда я мог бы анимировать представление по доступу к окну Layer.

Ниже приводится полная реализация моего открытия/закрытия анимации

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

HideOverlay функции

 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); 

     } 

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