UIWindow
1. UIWindow 的主要作用:1. 作为UIView的最顶层容器,包含应用显示所需要的所有的UIView。
2.传递触摸消息和键盘事件给UIView。
2. 如果我们创建的UIWindow需要处理键盘事件,那就需要合理的将其设置为keyWindow。keyWindow 是被系统设计用来接收键盘和其他非触摸事件的UIWindow。我们可以通过makeKeyWindow 和 resignKeyWindow方法来将自己创建的UIWindow实例设置为keyWindow.
#import <UIKit/UIKit.h> @interface PasswordInputWindow : UIWindow + (PasswordInputWindow *) sharedInstance; - (void)show; @end #import "PasswordInputWindow" @implementation PasswordInputWindow{ UITextField *_textField; } + (PasswordInputWindow *) sharedInstance{ static id sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ sharedInstance = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; }); return sharedInstance; } - (id)initWithFrame:(CGRect )frame{ self = [super initWithFrame:frame]; if (self){ } return self; } - (void)show{ [self makeKeyWindow]; }
3. 不要滥用UIWindow
例如 如果弹出界面明显属于某一个ViewController, 那么更适合把弹出的界面当做这个ViewController的view 的subView来实现。
浙公网安备 33010602011771号