需求
来源:互联网 发布:淘宝上的pvc桌布有毒吗 编辑:程序博客网 时间:2024/04/24 00:46
Coding应用中有一个点击出现遮罩层效果,这里把它抽离出来
首先用到了:XHRealTimeBlur 这个开源的控件,具体的实现可以去看看,是用属性绑定加CAGradientLayer实现的
将这个控件封装一层:
#import <UIKit/UIKit.h>@interface PopFliterView : UIView@property (assign) BOOL showStatus;@property (nonatomic, copy) void (^clickBlock)(NSInteger selectNum);@property (nonatomic, copy) void (^closeBlock)();- (instancetype)initWithFrame:(CGRect)frame items:(NSArray *)items;- (void)showMenuAtView:(UIView *)containerView;- (void)dismissMenu;@end
实现:
#import "PopFliterView.h"#import "XHRealTimeBlur.h"#import "pop.h"#import "LBMacroHeader.h"#import "LBCommonHeader.h"@interface PopFliterView ()@property (nonatomic, strong) XHRealTimeBlur *realTimeBlur;@property (nonatomic, strong) UIImageView* imageView;@end@implementation PopFliterView- (id)initWithFrame:(CGRect)frame items:(NSArray *)items{ self = [super initWithFrame:frame]; if (self) { self.showStatus = FALSE; [self setup]; } return self;}- (void)setup{ self.backgroundColor = [UIColor clearColor]; _realTimeBlur = [[XHRealTimeBlur alloc] initWithFrame:self.bounds]; _realTimeBlur.blurStyle = XHBlurStyleTranslucentWhite; _realTimeBlur.showDuration = 0.1; _realTimeBlur.disMissDuration = 0.2; typeof(self) __weak weakSelf = self; _realTimeBlur.willShowBlurViewcomplted = ^(void){ POPBasicAnimation *alphaAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha]; alphaAnimation.fromValue = @0.0; alphaAnimation.toValue = @1.0; alphaAnimation.duration = 0.3f; [weakSelf.imageView pop_addAnimation:alphaAnimation forKey:@"alphaAnimationS"]; }; _realTimeBlur.willDismissBlurViewCompleted = ^(void){ POPBasicAnimation *alphaAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha]; alphaAnimation.fromValue = @1.0; alphaAnimation.toValue = @0.0; alphaAnimation.duration = 0.2f; [weakSelf.imageView pop_addAnimation:alphaAnimation forKey:@"alphaAnimationE"]; }; _realTimeBlur.didDismissBlurViewCompleted = ^(BOOL finished){ [weakSelf removeFromSuperview]; }; _realTimeBlur.hasTapGestureEnable = YES; // 还可以在这里放置图片// _imageView = ({// // UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lufy.jpg"]];// [imageView setFrame:CGRectMake(0, 0, 150, 300)];// [imageView setCenter:self.center];// imageView;// }); [self addSubview:_imageView];}#pragma mark -- event & action- (void)showMenuAtView:(UIView *)containerView{ _showStatus = TRUE; [containerView addSubview:self]; [_realTimeBlur showBlurViewAtView:self];}- (void)dismissMenu{ _showStatus=FALSE; [_realTimeBlur disMiss];}@end
调用处:
#import "FliterMenuThirdViewController.h"#import "PopFliterView.h"// 宏参数#import "LBCommonHeader.h"#import "LBMacroHeader.h"@interface FliterMenuThirdViewController ()@property (nonatomic, strong) UIButton *button;@property (nonatomic, strong) PopFliterView *myFliterView;@end@implementation FliterMenuThirdViewController- (void)viewDidLoad{ [super viewDidLoad]; [self.view setBackgroundColor:[UIColor lightGrayColor]]; _button = [UIButton buttonWithType:UIButtonTypeCustom]; [_button setFrame:CGRectMake(0, 0, 45, 45)]; [_button setBackgroundImage:[UIImage imageNamed:@"filtertBtn_normal_Nav"] forState:UIControlStateNormal]; [_button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [_button setCenter:self.view.center]; [self.view addSubview:_button]; [self setupFliterView];}// 配置PopFliterView , 初始化- (void)setupFliterView{ _myFliterView = [[PopFliterView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height) items:nil]; __weak typeof(self) weakSelf = self; _myFliterView.clickBlock = ^(NSInteger pageIndex){ [weakSelf fliterBtnClose:TRUE]; }; _myFliterView.closeBlock = ^{ [weakSelf closeFliter]; };}- (void)closeFliter{ if ([_myFliterView showStatus]) { [_myFliterView dismissMenu]; }}- (void)fliterBtnClose:(BOOL)status{ [_button setImage:status?[UIImage imageNamed:@"filtertBtn_normal_Nav"]:[UIImage imageNamed:@"filterBtn_selected_Nav"] forState:UIControlStateNormal];}- (void)buttonClicked:(id)sender{ if (_myFliterView.showStatus) { [self fliterBtnClose:TRUE]; [_myFliterView dismissMenu]; } else { [self fliterBtnClose:FALSE]; [_myFliterView showMenuAtView:self.view]; }}@end
这样就可以实现带朦胧效果的遮罩了
但是我们还能更好地去实现这个功能,请看下一个文章
0 0
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求
- 需求分析之需求
- 什么是需求?软件需求?
- 创建型模式、结构型模式和行为型模式之间的关系
- 第一次使用面向对象了解php流程(供自己参考)
- 什么是servlet?---总结一
- 理解哈希表
- 搭建 rbac 后台系列教程(四)—— 创建左侧导航栏菜单
- 需求
- 五 数组与指针
- ubuntu 查看java安装包的位置
- 使用Mathtype自动编号和自动引用,并且转成pdf之后保持公式编号链接到公式
- java javadoc jar javac
- 2017阿里实习生招聘编程题之墓室
- 换11元钱问题,动态规划问题
- ScrollView 滚动视图
- 404. Sum of Left Leaves的C++解法