#import <UIKit/UIKit.h>
@interface CqCover : UIView
//显示蒙版
+ (void)coverShow;
//隐藏蒙版
+ (void)coverHide;
@end
-----------------------------------------------------
#import "CqCover.h"
#define keyWindow [UIApplication sharedApplication].keyWindow
@implementation CqCover
+ (void)coverShow{
CqCover *cover = [[CqCover alloc] initWithFrame:[UIScreen mainScreen].bounds];
cover.alpha = 0.6;
cover.backgroundColor = [UIColor grayColor];
[keyWindow addSubview:cover];
}
+ (void)coverHide{
for (UIView *cover in keyWindow.subviews) {
if ([cover isKindOfClass:self]) {
[cover removeFromSuperview];
}
}
}
#import <UIKit/UIKit.h>
@class CqPopMenu;
@protocol CqPopMenuDelegate <NSObject>
@optional
- (void)popMenuClickHide:(CqPopMenu *)popmenu;
@end
@interface CqPopMenu : UIView
/** 代理 */
@property(weak,nonatomic) id<CqPopMenuDelegate> delegate;
+ (instancetype)popMenu;
+ (instancetype)showInPoint:(CGPoint)point;
- (void)hideInPoint:(CGPoint)point andCompletion:(void(^)())completionBlock;
@end
---------------------------------------------------
#import "CqPopMenu.h"
#define keyWindow [UIApplication sharedApplication].keyWindow
@implementation CqPopMenu
- (void)hideInPoint:(CGPoint)point andCompletion:(void (^)())completionBlock{
[UIView animateWithDuration:0.5 animations:^{
self.center = point;
self.transform = CGAffineTransformMakeScale(0.01, 0.01);
}completion:^(BOOL finished) {
[self removeFromSuperview];
if (completionBlock) {
completionBlock();
}
}];
}
- (IBAction)ClickHide:(id)sender {
if ([self.delegate respondsToSelector:@selector(popMenuClickHide:)]) {
[self.delegate popMenuClickHide:self];
}
}
+ (instancetype)popMenu{
return [[NSBundle mainBundle] loadNibNamed:@"CqPopMenu" owner:self options:nil][0];
}
+ (instancetype)showInPoint:(CGPoint)point{
CqPopMenu *menu = [CqPopMenu popMenu];
menu.center = point;
[keyWindow addSubview:menu];
return menu;
}
- (void)ativity{
[CqCover coverShow];
CGFloat screenW = [UIScreen mainScreen].bounds.size.width * 0.5;
CGFloat screenH = [UIScreen mainScreen].bounds.size.height * 0.5;
CqPopMenu *menu = [CqPopMenu showInPoint:CGPointMake(screenW, screenH)];
menu.delegate = self;
}
- (void)popMenuClickHide:(CqPopMenu *)popmenu{
[popmenu hideInPoint:CGPointMake(44, 44) andCompletion:^{
[CqCover coverHide];
}];
}