animationUIView阿尔法的问题

我试图应用一个淡入淡出的程序在另一个顶部创build的UIView。

[UIView animateWithDuration:0.5 animations:^(void) { [self.view setAlpha:0]; } completion:^(BOOL finished){ [self.view removeFromSuperview]; }]; 

完成后的事件恰好在0.5秒之后被调用,但我没有看到任何淡入淡出(我应该看到底部的UIView)。

如果不是使用alpha,我把UIView的作品移开(我看到底部的UIView,而顶部的UIView滑出),所以它似乎是一个问题有关的阿尔法,但我不明白什么是错的!

 [UIView animateWithDuration:0.5 animations:^(void) { CGRect o = self.view.frame; o.origin.x = 320; self.view.frame = o; } completion:^(BOOL finished){ [self.view removeFromSuperview]; }]; 

我以前使用过alphaanimation,他们通常以这种方式工作…

尝试设置opaqueNO显式。 我有同样的问题和设置,解决了我的问题。 显然,不透明的意见似乎不与阿尔法。

信贷去Hampus Nilsson的评论。

  [UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self.view setAlpha:0]; } completion:^(BOOL finished) { [self.view removeFromSuperview]; }]; 

这将工作正确,你的褪色会更好,因为options:UIViewAnimationOptionCurveEaseInOut

我碰到了确切的问题。 在我的情况下,我想首先隐藏视图,所以我hiddentrue 。 我认为改变alpha值会自动改变hidden属性,但事实并非如此。

所以,如果你想要视图隐藏起来,将其alpha设置为0

我有完全相同的问题,没有任何build议为我工作。 我通过使用图层不透明度来克服问题。 这是用于显示图层的代码(使用Xamarin,但你会明白):

  //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) => { } ); 

这是淡出相同的zoomView

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

我遇到同样的问题在我的情况下,因为线程所以我最终在主线程中写animation块。

 dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{ View.alpha = 0.0f; } completion:^(BOOL finished) { }]; });