ios-Add UIWindow Mask

Source: Internet
Author: User

Development often encounter the need to add a translucent mask, such as all kinds of tips, such as window.

add masks on UIWindow layers

Priority Level

For example, a mask can also be added to a self.navigationController.view layer or on a self.tabBarController.view layer

Self.view < Self.navigationController.view < Self.tabBarController.view < UIWindow


UIWindow: Generally as a container for UIView

Application Scenarios

You can create a window when you need to display some controls to the top, and then add space to the window

Alipay, accounting software certification interface (gesture unlock) Most of them are made with UIWindow

Attention

1. Generally do not create windows at will, do not abuse, as long as the creation is automatically added to the interface (do not addsubview ...) , if misuse of windows can lead to an application's hierarchy confusion

2.window has a level, the higher the level is displayed in the top level (keyboard level is highest)

There are 3 levels by default: Uiwindowlevelnormal (0.0) < Uiwindowlevelalert (1000.0) < Uiwindowlevelstatusbar (2000.0)

can also be customized window.windowlevel = 4000.0;

UIWindow features

As long as the creation is automatically added to the interface

System pop-up Uialertview, pop-up keyboard, to text messages, calls, power shortages are also used UIWindow

If you need a window listener Click event you need to set the frame, because there is no frame after window creation

UIWindow *window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];

Remove window to direct window = nil in the click method;

Cover as frame is a semitransparent or transparent button for the [UIScreen Mainscreen].bounds]

UIWindow *window = [UIApplication Sharedapplication].keywindow;

[Window Addsubview:cover];


In the last case, a custom fingerprint lock window, where Touchidview is a custom view style for Xib, can be customized according to the actual needs and add agents and other methods.

#pragma mark-Add Touchidview window

-(void) popcoverview{

Setting masks

Self.coverview = [[Uiviewalloc]initwithframe:[uiscreenmainscreen].bounds];

Self.coverView.backgroundColor = [Uicolorblackcolor];

Self.coverView.alpha = 0.6;

Add Mask up window view

Self.touchidview = [[Nsbundlemainbundle] loadnibnamed:@ "Ddtouchidview" owner:selfoptions:nil].lastobject;

Self.touchidView.center =self.coverview.center;

Self.touchidView.delegate =self;

Implementing Pop-up Methods

UIWindow *window = [Uiapplicationsharedapplication].keywindow;

Window.windowlevel =uiwindowlevelnormal;

[Window AddSubview:self.coverView];

[Window AddSubview:self.touchidView];

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.