ios开发-新浪微博-09(下拉菜单封装一)
来源:互联网 发布:奥卡福 知乎 编辑:程序博客网 时间:2024/05/21 14:05
我们要对下来菜单封装
首先我们要考虑三件事情
1.创建下拉菜单
2.设置内容
3.显示
4.销毁
根据以上的需求 我们按照步骤完成即可
这里先对下拉菜单进行了初步的封装
#import <UIKit/UIKit.h>@interface QHDropdownMenu : UIView+(instancetype)menu;@property(nonatomic,strong)UIView *content;@property(nonatomic,strong)UIViewController *contentController;/** * 显示 */-(void)showFrom:(UIView *)from;/** * 销毁 */-(void)dismiss;@end
#import "QHDropdownMenu.h"@interface QHDropdownMenu()/** * 将来用来显示具体内容的容器 */@property(nonatomic,strong)UIImageView *containerView;@end@implementation QHDropdownMenu//懒加载一般用强指针//除非先创建-(UIImageView *)containerView{ if (!_containerView) { //添加一个灰色图片控件 UIImageView *containerView = [[UIImageView alloc]init]; containerView.image = [UIImage imageNamed:@"popover_background"]; containerView.width = 217; containerView.height = 217; containerView.userInteractionEnabled = YES; [self addSubview:containerView]; self.containerView = containerView; } return _containerView;}-(id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { //清除颜色 self.backgroundColor = [UIColor clearColor]; // //添加一个灰色图片控件// UIImageView *containerView = [[UIImageView alloc]init];// containerView.image = [UIImage imageNamed:@"popover_background"];// containerView.width = 217;// containerView.height = 217;// containerView.userInteractionEnabled = YES;// [self addSubview:containerView];// self.containerView = containerView; } return self;}+(instancetype)menu{ return [[self alloc]init];}-(void)setContent:(UIView *)content{ _content = content; //调整内部位置 content.x = 10; content.y = 15; //设置内容的宽度 content.width = self.containerView.width - 2*content.x; //设置灰色的高度 self.containerView.height = CGRectGetMaxY(content.frame)+10; //添加内容到灰色图片中 [self.containerView addSubview:content];}-(void)setContentController:(UIViewController *)contentController{ _contentController = contentController; self.content = contentController.view;}/** * 显示 */-(void)showFrom:(UIView *)from{ //1.获得最上面的窗口 UIWindow *window = [[UIApplication sharedApplication].windows lastObject]; //2.添加自己到窗口 [window addSubview:self]; //3.设置尺寸 创建出来都是全屏的 self.frame = window.bounds; //4.调整灰色图片的位置 self.containerView.x = (self.width - self.containerView.width)*0.5; self.containerView.y = 50; }/** * 销毁 */-(void)dismiss{ [self removeFromSuperview];}/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect { // Drawing code}*/@end
0 0
- ios开发-新浪微博-09(下拉菜单封装一)
- ios开发-新浪微博10-(下拉菜单的二次封装 完整版)
- 新浪微博开发七(下拉菜单的实现)
- ios开发-新浪微博08-下拉菜单的基本实现
- iOS-新浪微博开发-26-下拉刷新
- ios开发 -新浪微博(4)封装item 添加分类
- ios-新浪微博开发-22-封装标题按钮
- iOS开发——封装自己的下拉菜单
- iOS 怎么封装一个三级下拉菜单?
- 新浪微博开发(六)封装一个OauthUtils类
- 新浪微博开发之十六(封装网络工具)
- ios开发小项目——新浪微博(一)——OAuth认证
- 新浪微博开发(一)开发前介绍
- 下拉菜单(二) PopupWindow 封装实现
- 封装遮盖&下拉菜单
- 下拉选择菜单封装
- 下拉选择菜单封装
- 仿新浪微博IOS客户端(v5.2.8)——下拉菜单栏的实现
- Android开发之Intent.Action
- 上善若水
- Spinner 下拉框
- 笔试题:C语言中的字符串问题
- hdu~5025(bfs+状态压缩)
- ios开发-新浪微博-09(下拉菜单封装一)
- 计算机网络学习 :互联网与万维网的区别
- XML解析 JSON解析
- Effective C++——条款43(第7章)
- 调用系统的Camera和相册/压缩照片
- hdu 5023 A Corrupt Mayor's Performance Art(线段树+位运算)
- (新手向)幻想战境DEMO(二)
- Android 二维码扫描 YUV字节数组转换成bitmap
- Java语言的基础语法(二)