IOS-encapsulation dialog box

Source: Internet
Author: User

IOS-encapsulation dialog box

1. encapsulate the pop-up box, including setting the pop-up page and setting the pop-up location to disappear. The encapsulation is as follows:

 

#import 
 
  @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 = [[UIImageView alloc] init]; iv. image = [UIImage imageNamed: @ "popover_background"]; iv. width = 217; [self addSubview: iv]; _ containerView = iv;} return _ containerView;} # pragme initialize transparent background interface and pop-up 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 settings pop-up box content-(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] ;}# set the display position of pragme to the absolute position of 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 show the content of the current top window. A keyboard window is provided by default in ios8)

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.