IOS 自定义从底部弹上来的View
2016-06-22 19:36
495 查看
效果图:
//从底部向上弹起的UIView类源码
使用方法:
1.在一个ViewController中,初始化一个button,添加点击事件
2. 加载从底部向上弹起的UIView(如效果图所示)
3. 点击一下遮罩,页面会自动下去(从上向下)
//从底部向上弹起的UIView类源码
#import "TFSheetView.h" @interface TFSheetView() { UIView *_contentView; } @end @implementation TFSheetView - (id)initWithFrame:(CGRect)frame { if (self == [super initWithFrame:frame]) { [self initContent]; } return self; } - (void)initContent { self.frame = CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT); //alpha 0.0 白色 alpha 1 :黑色 alpha 0~1 :遮罩颜色,逐渐 self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]; self.userInteractionEnabled = YES; [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMissView)]]; if (_contentView == nil) { _contentView = [[UIView alloc]initWithFrame:CGRectMake(0, kDEVICEHEIGHT - 216, kDEVICEWIDTH, 216)]; _contentView.backgroundColor = [UIColor redColor]; [self addSubview:_contentView]; } } - (void)loadMaskView { } //展示从底部向上弹出的UIView(包含遮罩) - (void)showInView:(UIView *)view { if (!view) { return; } [view addSubview:self]; [view addSubview:_contentView]; [_contentView setFrame:CGRectMake(0, kDEVICEHEIGHT, kDEVICEWIDTH, 216)]; [UIView animateWithDuration:0.3 animations:^{ self.alpha = 1.0; [_contentView setFrame:CGRectMake(0, kDEVICEHEIGHT - 216, kDEVICEWIDTH, 216)]; } completion:nil]; } //移除从上向底部弹下去的UIView(包含遮罩) - (void)disMissView { [_contentView setFrame:CGRectMake(0, kDEVICEHEIGHT - 216, kDEVICEWIDTH, 216)]; [UIView animateWithDuration:0.3f animations:^{ self.alpha = 0.0; [_contentView setFrame:CGRectMake(0, kDEVICEHEIGHT, kDEVICEWIDTH, 216)]; } completion:^(BOOL finished){ [self removeFromSuperview]; [_contentView removeFromSuperview]; }]; } @end
使用方法:
1.在一个ViewController中,初始化一个button,添加点击事件
- (void)loadBtnView { UIButton *_loginButton = [[UIButton alloc]initWithFrame:CGRectMake(40, 220, kDEVICEWIDTH - 40*2, 40)]; [_loginButton setTitle:@"加载" forState:UIControlStateNormal]; _loginButton.backgroundColor = [UIColor grayColor]; [_loginButton addTarget:self action:@selector(loadClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_loginButton]; }
2. 加载从底部向上弹起的UIView(如效果图所示)
- (void)loadClicked { //[_sheetView showInView:self.view]; _tfSheetView = [[TFSheetView alloc]init]; [_tfSheetView showInView:self.view]; }
3. 点击一下遮罩,页面会自动下去(从上向下)
相关文章推荐
- ios流媒体直播整个框架介绍(HLS、RTSP)
- IOS could not find developer disk image 真机设备不支持
- iOS开发——WAVE音频文件解析
- ios -- NSNotification(通知)
- ios内存管理深入解析
- iOS-程序启动
- iOS9URLScheme适配(白名单配置)
- 使用Xcode7的Instruments检测解决iOS内存泄露
- MRC到ARC的自动转换
- iOS静态库中打包图片资源
- iOS蓝牙编程
- iOS 8显示应用角标
- iOS _SVN错误小结
- iOS --- KVO
- iOS开发之第三方分享QQ分享,史上最新最全第三方分享QQ方式实现
- iOS 图片背景虚化 高斯模糊
- iOS开发之观察者模式初探
- 有关iOS热更新
- Method swizzling
- iOS解锁界面的"滑动来解锁"闪烁动画效果