Q:

Changing UIview color after tapping it but before action with IOS

Actually I've put a tap gesture recognizer on an UIView to show another screen and I want its color to change right before the next screen is presented.
I'm creating the Tap Gesture like:
        tapGesture = new UITapGestureRecognizer(HighlightLine);
        myview.UserInteractionEnabled = true;
        myview.AddGestureRecognizer (tapGesture);

And the code to change the color and push the new UIViewController:
    private void HighlightLine()
    {
        var view = tapGesture.View;
        var loc = tapGesture.LocationInView(view);
        var subview = view.HitTest(loc, null);

        while(subview.Superview != null && subview.Tag != 1000) //find the right view
            subview = subview.Superview;

            if (subview.Tag == 1000)
            {
                subview.BackgroundColor = new UIColor(0.9f, 0.91f, 0.95f, 1f);
                var vc = this.Storyboard.InstantiateViewController("ScrollSaisie") as ScrollSaisie;
                parent.NavigationController.PushViewController(vc, true);
        }
    }

Everything works individually (if I don't push the viewController the view color changes and if I push the viewController it shows) but as the view is paused when the second viewController shows, the color is not changed before the second viewController closes.
I was able to solve the problem by using a timer but I did not think it was a very good solution.
Is there another solution?

A:

The issue is that changes to UIView's do not apply until the end of the function they are being applied in. Here you are pushing a new view controller before the view has a change to change its color. A simple way to get the effect that you want is to just use an animation with a completion block.
Swift:
UIView.animate(withDuration: 0.33, delay: 0, options: .curveLinear, animations: {
    // Change view color
}, completion: { _ in
    // Push new ViewController
})

Xamarin:
UIView.Animate(0.33, 0, UIViewAnimationOptions.CurveLinear,
    () => {
        subview.BackgroundColor=new UIColor(0.9f, 0.91f, 0.95f, 1f);
    },
    () => {
        var vc = this.Storyboard.InstantiateViewController("ScrollSaisie") as ScrollSaisie;
        parent.NavigationController.PushViewController(vc, true); 
    }
);

