这是我写的代码,我添加为子视图的所有视图都是我想要在用户界面上方的模糊视图下方的.@H_403_3@
在演示视图控制器中,我将屏幕截图显示给模糊视图控制器,然后再应用模糊.@H_403_3@
在呈现视图控制器:@H_403_3@
- (UIImage *)vIEwImage { CGSize size = CGSizeMake(self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height); UIGraphicsBeginImageContext(size); [self.vIEw drawVIEwHIErarchyInRect:(CGRect){CGPointZero,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height} afterScreenUpdates:YES]; UIImage *image = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); return image;}
在模态视图控制器:@H_403_3@
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; [self.vIEw addSubvIEw:[[UIImageVIEw alloc] initWithImage:self.backgroundImage]]; //self.backgroundImage is the image that the method above returns,it's a screenshot of the presenting vIEw controller. UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStylelight]; UIVisualEffectVIEw *blurEffectVIEw = [[UIVisualEffectVIEw alloc] initWithEffect:blurEffect]; [blurEffectVIEw setFrame:self.vIEw.bounds]; [self.vIEw addSubvIEw:blurEffectVIEw]; [self.vIEw bringSubvIEwToFront:self.cancelbutton]; [self.vIEw bringSubvIEwToFront:self.TitleLabel]; [self.vIEw bringSubvIEwToFront:self.tableVIEw];}解决方法 使用UIVisualEffectVIEw时,不需要生成快照.尝试删除“ – (UIImage *)vIEwImage”,并在模型视图控制器中添加一个与视图控制器视图大小匹配的UIVisualEffectVIEw,并将所有“控制”视图添加到UIVisualEffectVIEw的contentVIEw中.
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStylelight]; UIVisualEffectVIEw *blurEffectVIEw = [[UIVisualEffectVIEw alloc] initWithEffect:blurEffect]; [blurEffectVIEw setFrame:self.vIEw.bounds]; [self.vIEw addSubvIEw:blurEffectVIEw]; [blurEffectVIEw.contentVIEw addSubvIEw:self.cancelbutton]; [blurEffectVIEw.contentVIEw addSubvIEw:self.TitleLabel]; [blurEffectVIEw.contentVIEw addSubvIEw:self.tableVIEw];}
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIVisualEffectView/index.html@H_403_3@
我没有尝试过故事板,但这是一个经过测试的工作片段.可能是一个开始的好地方.翻译成objc应该是挺直的@H_403_3@
这是演示视图控制器@H_403_3@
import UIKitclass BaseVIEwController: UIVIEwController {init(nibname nibnameOrNil: String?,bundle nibBundleOrNil: NSBundle?) { super.init(nibname: nibnameOrNil,bundle: nibBundleOrNil)}overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() var backgroundImage = UIImageVIEw(image: UIImage(named: "image")) self.vIEw.addSubvIEw(backgroundImage) var button = UIbutton(frame: CGRectMake(0,100,320,50)) button.setTitle("Lorem Ipsum",forState: UIControlState.normal) button.backgroundcolor = UIcolor.redcolor() button.addTarget(self,action: "onbuttonTapped:",forControlEvents: UIControlEvents.touchUpInsIDe) self.vIEw.addSubvIEw(button)}func onbuttonTapped(sender: UIbutton?) { var modal = ModalVIEwController(nibname: nil,bundle: nil) modal.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext self.presentVIEwController(modal,animated: true,completion: {})}}
这是模态@H_403_3@
import UIKitclass ModalVIEwController: UIVIEwController {init(nibname nibnameOrNil: String?,bundle: nibBundleOrNil)}overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() self.vIEw.backgroundcolor = UIcolor.clearcolor() let effect = UIBlurEffect(style: UIBlurEffectStyle.light) let blurVIEw = UIVisualEffectVIEw(effect: effect) blurVIEw.frame = self.vIEw.bounds self.vIEw.addSubvIEw(blurVIEw)}}总结
以上是内存溢出为你收集整理的ios – 如何使用UIBlurEffect与模态视图控制器?全部内容,希望文章能够帮你解决ios – 如何使用UIBlurEffect与模态视图控制器?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)