IOS 自定义从底部弹上来的View
来源:互联网 发布:网络运营提成方案 编辑:程序博客网 时间:2024/05/16 10:51
效果图:
//从底部向上弹起的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. 点击一下遮罩,页面会自动下去(从上向下)
1 0
- IOS 自定义从底部弹上来的View
- iOS自定义从底部弹上来的View
- 自定义从底部出现的Dialog
- 一个典型的从下部弹上来的Dialog
- Android底部弹出的View,可自定义布局
- Android底部弹出的View,可自定义布局
- [转]Android底部弹出的View,可自定义布局
- 自定义Behavior实现底部View的平移动画
- # 仿QQ底部导航栏的自定义view
- BottomDialog 一个自定义的从底部弹出的 dialog,仿照微博的分享弹框
- android自定义popwindow,并且有从底部弹出的动画
- 从xml inflate自定义的View
- 自定义仿iOS的ActionSheet底部Dialog的样式
- Android模拟IOS风格的自定义Dialog底部弹窗案例
- 从底部弹出来一个view动画
- Android自定义View底部连续圆环效果
- android自定义view底部可上拉页面
- ios UIImagePickerController 添加一个自定义的view。
- Linux下的inode记录
- iOS开发 - 第02篇 - UI进阶 - 16 - 彩票(第三天)
- IOS-UIImageView
- 二叉树的建立与递归遍历C语言版
- git push 操作代码回退
- IOS 自定义从底部弹上来的View
- Spark RDD使用详解1--RDD原理
- 阻止冒泡的兼容写法
- Android图片setBackgroundResource和setImageResource的区别
- Java...和泛型
- 【洛谷2038 无线网络发射器选址】【模拟】
- android:configChanges 设置 (导致游戏里不能输入文字到输入框)
- CentOS6.7 Linux升级内核
- #define用法