目前,当用户按下按钮时,我正在处理一个带有MapView的项目,该项目会显示一个modalView。
modalView使用iOS 8的典型模糊效果。
问题是,我可以使用模糊效果呈现Modelview,并且可以解除它,但我无法移除地图的模糊效果。
当前代码:
ViewController.m
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)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)dismisModal:(id)sender {
[_audioPlayer stop];
[self dismissViewControllerAnimated:YES completion:nil];
}
如何在解除modalView时从mapView中删除blur SubView?
答案 0 :(得分:1)
这就是我设法让模态模糊起作用的方法!
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
}
}
}
}