OStack程序员社区-中国程序员成长平台

标题: ios - 关闭模态视图后删除模态模糊效果 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:44
标题: ios - 关闭模态视图后删除模态模糊效果

目前我正在使用 MapView 开发一个项目,当用户按下按钮时,它会呈现一个模态视图。

modalView 使用了 iOS 8 典型的 Blur 效果。

问题是,我可以呈现带有模糊效果的模型 View ,并且可以将其关闭,但我无法移除 map 的模糊效果。

当前代码:

ViewController.m

- (void)actionSheetUIActionSheet *)actionSheet clickedButtonAtIndexNSInteger)buttonIndex {
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
    if  ([buttonTitle isEqualToString"Set a alarm"]) {

        [self blurEffectMethod];

        AlarmViewController *modal = [self.storyboard instantiateViewControllerWithIdentifier"setAlarm"];
        modal.transitioningDelegate = self;
        modal.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        [self presentViewController:modal animated:YES completion:nil]

-(void)blurEffectMethod {
    UIVisualEffect *blurEffect;
    blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *visualEffectView;

    if (_radiusSlider.hidden == NO) {
        visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        visualEffectView.frame = _mapView.bounds;
        [_mapView addSubview:visualEffectView];
        //Hide Bars & Slider
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        _toolBar.hidden = YES ;
        _radiusSlider.hidden= YES;
        _sliderIndicator.hidden = YES;
    }

}

ModelViewController.m

- (IBAction)dismisModalid)sender {
    [_audioPlayer stop];
    [self dismissViewControllerAnimated:YES completion:nil];
}

如何在关闭 modalView 的同时从 mapView 中删除模糊 SubView?



Best Answer-推荐答案


这就是我设法让模态模糊工作的方法!

let vc = UIViewController()
vc.view = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
vc.modalPresentationStyle = .OverFullScreen

let nc = UINavigationController(rootViewController: vc)
nc.modalPresentationStyle = .OverFullScreen

presentViewController(nc, animated: true, completion: nil)

这里我在 prepareForSegue 上使用 .OverFullScreen 标志。在我的 viewControllers 上设置了一个模糊 UIVisualEffectView

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    if segue.identifier == "LifeEventSegue" {
        if let nc = segue.destinationViewController as? UINavigationController {
            nc.modalPresentationStyle = .OverFullScreen
            if let vi = nc.viewControllers.first as? UIViewController {
                vi.modalPresentationStyle = .OverFullScreen
            }
        }
    }
}

关于ios - 关闭模态视图后删除模态模糊效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26492871/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4