2017-12-21 2 views
0

정방향으로 만 6 자리 확인 코드를 입력하고 싶습니다. 왼쪽에서 오른쪽으로, UITextfield에서 오른쪽에서 왼쪽으로 삭제하는 것입니다. 텍스트 필드 사이에 집중할 수 없습니다. 텍스트 상자 값을 삭제하거나 변경하려면 오른쪽에서 삭제하고 가장 왼쪽 텍스트 상자에 도달해야합니다. 당신은 우리가보기를 만들 수 있습니다,UItextfield가있는 xamarin IOS에서만 앞으로 및 뒤로 단어 텍스트 박스 포커스를 만드시겠습니까?

Verification code screen

+0

효과를 얻었습니까? –

답변

1

첫째 이미지 아래에보고처럼 편집 할 수있는 텍스트 뷰를 추가 할 수 있습니다 그리고 우리가를 표시하기 위해 여섯 개 라벨을 그릴 수

UIView containView = new UIView(new CGRect(0, 200, 300, 50)); 
View.AddSubview(containView); 

UITextView textView = new UITextView(); 
textView.TintColor = UIColor.Clear; 
textView.BackgroundColor = UIColor.Clear; 
textView.TextColor = UIColor.Clear; 
textView.Frame = containView.Bounds; 
textView.Delegate = new MyTextViewDelegate(this); 
textView.KeyboardType = UIKeyboardType.NumberPad; 
containView.AddSubview(textView); 

숫자, 6 개의 포인터 줄, 또한 아래쪽 줄과 같이 :

for (int i = 0; i < 6; i++) 
{ 
    UILabel label = new UILabel(); 
    label.Frame = new CGRect(i * 50, 0, 50, 50); 
    label.TextAlignment = UITextAlignment.Center; 
    label.TextColor = UIColor.Black; 
    containView.AddSubview(label); 
    labelArr.Add(label); 

    UIView pointerLine = new UIView(new CGRect(i * 50 + 25, 12, 1, 26)); 
    pointerLine.BackgroundColor = UIColor.Blue; 
    containView.AddSubview(pointerLine); 
    pointerLine.Layer.AddAnimation(opacityAnimation(), "kOpacityAnimation"); 
    pointlineArr.Add(pointerLine); 
    if (i > 0) pointerLine.Hidden = true; 

    UIView line = new UIView(new CGRect(i * 50 + 5, 48, 40, 2)); 
    line.BackgroundColor = UIColor.Gray; 
    containView.AddSubview(line); 
    lineArr.Add(line); 
} 

편집 할 때 pointerLine을 깜박이게하려면 같은 pointerLine에 애니메이션을 추가 : 우리가 추가 또는 번호를 삭제하려고 할 때 마침내

CABasicAnimation opacityAnimation() 
{ 
    CABasicAnimation opacityAnimation = CABasicAnimation.FromKeyPath("opacity"); 
    opacityAnimation.From = NSNumber.FromNFloat(1); 
    opacityAnimation.To = NSNumber.FromNFloat(0); 
    opacityAnimation.Duration = 0.9; 
    opacityAnimation.RepeatCount = float.MaxValue; 
    opacityAnimation.RemovedOnCompletion = true; 
    return opacityAnimation; 
} 

우리가 당신의 효과를 얻을 수있는 텍스트 뷰의 위임에 몇 가지 설정을 할 수 있습니다. 이 파일을 참조 할 수있는 대표 파일입니다.

public class MyTextViewDelegate : UITextViewDelegate 
{ 
    ViewController superViewController; 

    public MyTextViewDelegate(ViewController viewController) 
    { 
     superViewController = viewController; 
    } 

    public override void Changed(UITextView textView) 
    { 
     string verStr = textView.Text.Replace(" ", ""); 


     for (int i = 0; i < superViewController.labelArr.Count; i++) 
     { 
      UILabel label = superViewController.labelArr[i]; 
      UIView pointerLabel = superViewController.pointlineArr[i]; 

      if (i < verStr.Length) 
      { 
       changeViewLayer(i, true); 
       label.Text = verStr.Substring(i, 1); 

      } 
      else 
      { 
       changeViewLayer(i, false); 
       label.Text = ""; 
      } 
      pointerLabel.Hidden = true; 
     } 

     if (verStr.Length >= 6) 
     { 
      textView.Text = verStr.Substring(0, 6); 
      endEdit(); 
      return; 
     } 
     else 
     { 
      superViewController.pointlineArr[verStr.Length].Hidden = false; 
     } 

    } 

    void endEdit() 
    { 
     superViewController.View.EndEditing(true); 
    } 

    void changeViewLayer(int index, bool isHidden) 
    { 
     UIView line = superViewController.lineArr[index]; 

     if (isHidden) 
     { 
      line.BackgroundColor = UIColor.Red; 
     } 
     else 
     { 
      line.BackgroundColor = UIColor.Gray; 
     } 
    } 
} 
관련 문제