1. Package Pop-up box, including setting pop-up screen to set pop-up location popup disappears and so on. Probably encapsulated as follows
#import <UIKit/UIKit.h> @interface wbdropdownmenu:uiview@property (nonatomic,strong) UIView *contentview;@ Property (Nonatomic,strong) Uiviewcontroller *cntcontroller;+ (instancetype) menu;-(void) Showfrom: (UIView *) view;-( void) dismiss; @end
2. Its implementation is as follows:
#import "WBDropdownMenu.h" @interface Wbdropdownmenu () @property (nonatomic, weak) Uiimageview *containerview;@ End@implementation wbdropdownmenu-(Uiimageview *) containerview{if (!_containerview) {Uiimageview *iv=[[UIImage View alloc] init]; Iv.image=[uiimage imagenamed:@ "Popover_background"]; iv.width=217; [Self addsubview:iv]; _containerview=iv; } return _containerview;} #pragme Initialize transparent background interface and popup box background-(Instancetype) initWithFrame: (cgrect) frame{self = [super Initwithframe:frame]; if (self) {self.frame=[uiscreen mainscreen].bounds; Self.backgroundcolor=[uicolor Clearcolor]; [Self containerview].userinteractionenabled=yes; } return self;} + (Instancetype) menu{return [[Wbdropdownmenu alloc] init];} #pragme Set Popup contents-(void) Setcontentview: (UIView *) contentview{contentview.x=10; contentview.y=15; Contentview.width=self.containerview.width-2 * contentview.x; Self.containerview.height=cgrectgetmaxy (cOntentview.bounds) +25; [Self.containerview Addsubview:contentview];} -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{[self Dismiss];} Another form of #pragme extended content view viewcontroller-(void) Setcntcontroller: (Uiviewcontroller *) cntcontroller{_cntcontroller= Cntcontroller; [Self setcontentview:_cntcontroller.view];} #pragme set the display position to the absolute position of the Windiow-(void) Showfrom: (UIView *) view{uiwindow *window= [[UIApplication sharedapplication]. Windows Lastobject]; [Window addsubview:self]; CGRect Absrect=[view convertRect:view.bounds toview:self]; Self.containerview.y=cgrectgetmaxy (Absrect); Self.containerview.midx=cgrectgetmidx (Absrect); }-(void) dismiss{[self removefromsuperview];} @end
3. The call is as follows:
Self.menu=[wbdropdownmenu menu]; Wbdropdownviewcontroller *tableviewcontroller=[[wbdropdownviewcontroller alloc] init]; tableviewcontroller.tableview.height=44*3; [Self.menu Setcntcontroller:tableviewcontroller]; [Self.menu Showfrom:target];
(Most pop-up boxes appear as the contents of the current top window, and a keyboard window is started by default in iOS8)
ios-Package pop-up box