美文网首页
ios 使用UIwindow自制弹窗

ios 使用UIwindow自制弹窗

作者: Mjs | 来源:发表于2018-05-15 15:04 被阅读0次

创建一个简单的弹窗,先定义一个全局的uiwindow。

在使用时创建并覆盖全局大小。设置背景色的透明度,使用户可以看到下方,设置windowlevel小于警告框,设置window为显示。

    self.CartWindow = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, Screen_width, Screen_height)];

    self.CartWindow.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];

    self.CartWindow.windowLevel = UIWindowLevelAlert-10;

    self.CartWindow.layer.masksToBounds = YES;

    self.CartWindow.hidden=NO;

随后创建viewcontroller使之显示在window上

UIViewController *cartVC = [[UIViewController alloc]init]

在VC的返回事件中添加销毁事件

@Weakify(self);

cartVC.closeBlock = ^() {

@Strongify(self);

            [weakSelf dismissWindow];

    };

    self.CartWindow.rootViewController = cartVC;

    cartVC.view.frame=CGRectMake(0, Screen_height, Screen_width, Screen_height);

    添加弹出动画

    [UIView animateWithDuration:0.3 delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{

        cartVC.view.frame=CGRectMake(0, 0, Screen_width, Screen_height);

    } completion:nil];

//销毁window

-(void)dismissWindow

{

    UIViewController *vc=self.CartWindow.rootViewController;

    self.CartWindow.backgroundColor=[UIColor clearColor];

@Weakify(self);

    [UIView animateWithDuration:0.3f animations:^{

        vc.view.frame=CGRectMake(0, Screen_height, Screen_width, Screen_height);

    } completion:^(BOOL finished) {

@Strongify(self);

        self.CartWindow.hidden = YES;

        self.CartWindow = nil;

    }];

}

//@Weakify(self)和@Strongify(self)为ReactiveCocoa里方法

在自定义的UIviewcontroller中设置背景色为透明,并添加一个覆盖真个view的Button,模仿点击灰色透明区域返回

————菜鸟

相关文章

  • ios 使用UIwindow自制弹窗

    创建一个简单的弹窗,先定义一个全局的uiwindow。 在使用时创建并覆盖全局大小。设置背景色的透明度,使用户可以...

  • UIWindow的基本使用

    二、使用UIWindow 1、简介在iOS App中,UIWindow是最顶层的界面内容,我们使用UIWindow...

  • iOS关于UIWindow

    UIWindow简介: 在iOS App中,UIWindow是最顶层的界面内容,我们使用UIWindow和UIVi...

  • UIWindow笔记

    在iOS App中,UIWindow是最顶层的界面内容,我们使用UIWindow和UIView来呈现界面。UIWi...

  • iOS开发进阶 第十二章 UIWindow

    在iOS应用中,我们使用UIWindow和UIView来呈现界面。UIWindow并不包含任何默认的内容,但是当他...

  • UIView, CALayer

    简介 在iOS中使用UIWindow和UIView在屏幕上显示APP的内容。UIWindow为APP提供了一个底层...

  • UIWindow

    UIWindow基本使用 ios程序启动完毕后,创建的第一个视图控件就是UIWindow 如果指定了main,系统...

  • UIWindows介绍

    简介 UIWindow 是最顶层的界面容器,下面介绍一些关于它的使用技巧在iOS App中,UIWindow是最顶...

  • 屏幕旋转

    屏幕旋转 推荐文档 了解UIWindow——UIWindow实践 iOS屏幕旋转问题总结 IOS:屏幕旋转与变换 ...

  • iOS 开发- UI篇-UIWindow介绍

    UIWindow 简单介绍原文链接? iOS开发UI篇—UIWindow简单介绍 一、简单介绍 UIWindow是...

网友评论

      本文标题:ios 使用UIwindow自制弹窗

      本文链接:https://www.haomeiwen.com/subject/ofohjttx.html