首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIVisualEffectView in iOS 10

UIVisualEffectView in iOS 10
EN

Stack Overflow用户
提问于 2016-09-24 00:47:58
回答 3查看 4.8K关注 0票数 31

我将介绍一个包含UIViewController的UIVisualEffectView,如下所示:

代码语言:javascript
复制
-(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中的视图控制器?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-09-26 18:20:15

iOS 10改变了UIVisualEffectView的工作方式,它打破了许多严格意义上“合法”但以前有效的用例。坚持文档化,您不应该在UIVisualEffectView中衰落,这就是使用UIModalTransitionStyleCrossDissolve时所发生的情况。现在,它似乎在iOS 10上被打破了,还有视觉效果视图的掩蔽,以及其他。

在您的示例中,我建议使用一个简单的修复方法,它还将创造比以前更好的效果,并且在iOS 9和10上都支持。创建一个自定义表示,而不是淡入视图,将effect属性从nil动画到模糊效果。如果需要,可以淡入视图层次结构的其余部分。这将整齐地动画模糊半径,类似于它的外观,当你拉下主屏幕图标。

票数 27
EN

Stack Overflow用户

发布于 2016-09-27 12:25:15

代码语言:javascript
复制
    UIView.animate(withDuration: 0.5) {
        self.effectView.effect = UIBlurEffect(style: .light)
    }

在iOS9和10上都进行了测试。

票数 5
EN

Stack Overflow用户

发布于 2016-12-15 12:17:41

当ViewController出现时,模糊父视图控制器下面的代码。在iOS9和10上都测试过。

代码语言:javascript
复制
@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];
    }];
}

@end
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39671408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档