Problems animating UIView alpha

后端 未结 6 1982
野趣味
野趣味 2020-12-06 19:17

I\'m trying to apply a fade to an UIView I created programmatically on the top of another.

[UIView animateWithDuration:0.5 animations:^(void) {
    [self.vie         


        
6条回答
  •  星月不相逢
    2020-12-06 19:37

    I had exactly the same problem, and none of the suggestions worked for me. I overcame the problem by using the layer opacity instead. This is the code for showing the layer (using Xamarin, but you'll get the idea):

            //Enter the view fading
            zoomView.Layer.Opacity = 0;
    
            UIApplication.SharedApplication.KeyWindow.RootViewController.View.Add(zoomView);
    
            UIView.AnimateNotify(
                0.15, // duration
                () => { zoomView.Layer.Opacity = 1.0f },
                (finished) => { }
            );
    

    And this is for fading out the same zoomView

    UIView.AnimateNotify(
                    0.15, // duration
                    () => { zoomView.Layer.Opacity = 0; },
                    (finished) =>
                    {
                        if (finished)
                        {
                            zoomView.RemoveFromSuperview();
                        }
                    }
                );
    

提交回复
热议问题