1

So there is a UITextField and I have a limit of characters on the field. If user tries to enter anything bigger, UIView appears. I already have that part animated. Here is what I have:

public void animateHoursMesg() {

    var HoursMesgExpandPos = new PointF (248.0f, 273.0f);
    var HoursMesgInitPos = new PointF (400.0f, 273.0f);
    UIView.Animate (
        duration: 0.3f,
        delay: 0,
        options: UIViewAnimationOptions.CurveEaseInOut,
        animation: () => {
            if (Flag_HoursMesg) {
                view_HoursLimitMesg.Center = HoursMesgInitPos;
                Flag_HoursMesg = false;
            } else {
                view_HoursLimitMesg.Center = HoursMesgExpandPos;
                Flag_HoursMesg = true;
            }
        },
        completion: () => {
        }
    );
}

The problem is I want this view to animate away 5 seconds after it appears.

Can someone please help me with this?

Thank you for your time.

ᴛʜᴇᴘᴀᴛᴇʟ
  • 4,466
  • 5
  • 39
  • 73

2 Answers2

2

In your completion block on the animate method, use an NSTimer to schedule a block to execute 5 seconds from then.

[NSTimer scheduledTimerWithTimeInterval:5.0
                                 target:self
                               selector:@selector(animateAway)
                               userInfo:nil
                                repeats:NO];

Then just create another method for the animateAway that reverses your previous animation.

kljhanson
  • 136
  • 3
0

In the completion block of the animation, you can run a different animation to animate the view away with a delay of 5 seconds.

chetem
  • 502
  • 3
  • 10