我将介绍一个包含UIViewController的UIVisualEffectView,如下所示:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"segueBlur" sender:nil];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"segueBlur"]) {
((UIViewController *)segue.destinationViewController).providesPresentationContextTransitionStyle = YES;
((UIViewController *)segue.destinationViewController).definesPresentationContext = YES;
((UIViewController *)segue.destinationViewController).modalPresentationStyle = UIModalPresentationOverFullScreen;
}
}如您所见,我使用的是UIModalPresentationStyleOverFullScreen,以便当出现带有模糊的视图控制器时,模糊将被“应用”到呈现它的视图控制器的内容中;segue具有交叉溶解转换风格。
效果看上去和预期的一样。然而,在iOS 9中,表示比在iOS 10中平滑。在iOS 10中,当视图控制器出现时,它看起来像是一个2步动画,而在iOS 9中,模糊化是立即应用的。
一张图片值一千字,所以我上传了一段视频,展示了这种奇怪的行为:
UIVisualEffectView iOS 9 vs iOS 10
我的问题是:如何在iOS 10中呈现iOS 9中的视图控制器?
发布于 2016-09-26 18:20:15
iOS 10改变了UIVisualEffectView的工作方式,它打破了许多严格意义上“合法”但以前有效的用例。坚持文档化,您不应该在UIVisualEffectView中衰落,这就是使用UIModalTransitionStyleCrossDissolve时所发生的情况。现在,它似乎在iOS 10上被打破了,还有视觉效果视图的掩蔽,以及其他。
在您的示例中,我建议使用一个简单的修复方法,它还将创造比以前更好的效果,并且在iOS 9和10上都支持。创建一个自定义表示,而不是淡入视图,将effect属性从nil动画到模糊效果。如果需要,可以淡入视图层次结构的其余部分。这将整齐地动画模糊半径,类似于它的外观,当你拉下主屏幕图标。
发布于 2016-09-27 12:25:15
UIView.animate(withDuration: 0.5) {
self.effectView.effect = UIBlurEffect(style: .light)
}在iOS9和10上都进行了测试。
发布于 2016-12-15 12:17:41
当ViewController出现时,模糊父视图控制器下面的代码。在iOS9和10上都测试过。
@interface ViewController () <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning>
@property (nonatomic) UIVisualEffectView *blurView;
@end
@implementation ViewController
- (instancetype)init
{
self = [super init];
if (!self)
return nil;
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.transitioningDelegate = self;
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.blurView = [UIVisualEffectView new];
[self.view addSubview:self.blurView];
self.blurView.frame = self.view.bounds;
}
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
return self;
}
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
return 0.3;
}
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIView *container = [transitionContext containerView];
[container addSubview:self.view];
self.blurView.effect = nil;
[UIView animateWithDuration:0.3 animations:^{
self.blurView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
} completion:^(BOOL finished) {
[transitionContext completeTransition:finished];
}];
}
@endhttps://stackoverflow.com/questions/39671408
复制相似问题