前面写了弹出动画两个,今天做商城时又用到了,看着这个用着蛮普遍的,所以记了下来

//
//  mallMoreView.h
//  XQB
//
//  Created by City--Online on 15/7/6.
//
//

#import <UIKit/UIKit.h>

typedef  void (^SelectMallMoreMenu)(NSInteger index);
@interface mallMoreView : UIView

//单例
+ (mallMoreView *)sharedManager;

//block传值
@property(nonatomic,strong) SelectMallMoreMenu selectMallMoreMenu;

@property(nonatomic,strong) NSArray *titles;
@property(nonatomic,strong) UITableView *tableView;

//window全屏显示
-(void)showInWindow;

// View中显示
-(void)showInView:(UIView*)view;

//在父视图view的相对位置为Frame
-(void)showInView:(UIView*)view withFrame:(CGRect)frame;

//消失视图
-(void)dismissView;
@end
//
//  mallMoreView.m
//  XQB
//
//  Created by City--Online on 15/7/6.
//
//

#import "mallMoreView.h"
#import "Global.h"
@interface mallMoreView ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,assign) BOOL open;
@end

@implementation mallMoreView

+ (mallMoreView *)sharedManager
{
    static mallMoreView *managerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        managerInstance = [[self alloc] init];
        managerInstance.backgroundColor=[UIColor colorWithWhite:0.1 alpha:0.1];

    });
    return managerInstance;
}
-(void)showInWindow
{

    [self showInView:[UIApplication sharedApplication].keyWindow];
}
-(void)showInView:(UIView*)view
{
    [self showInView:view withFrame:CGRectMake(, , view.frame.size.width, view.frame.size.height)];

}
-(void)showInView:(UIView*)view withFrame:(CGRect)frame
{
    if (_open) {
        [self dismissView];
        return;
    }
    _open=true;

    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissView)];
    [self addGestureRecognizer:tapGesture];
    self.frame=CGRectMake(, , frame.size.width, frame.size.height);

    self.alpha=0.0;

    if (_tableView==nil) {
        _tableView=[[UITableView alloc]init];
    }
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=[UIColor colorWithWhite:0.2 alpha:0.5];
    _tableView.tableHeaderView=[[UIView alloc]initWithFrame:CGRectZero];
    _tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

    //动画效果
    [UIView animateWithDuration: options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.alpha=1.0;
        _tableView.hidden=NO;
      } completion:nil
    ];
    [view addSubview:self];

    //要将TableView添加到view而不是self,否则不能选中TableView
    [view addSubview:_tableView];

}
-(void)dismissView
{
    _open=false;
    [UIView animateWithDuration: options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.alpha=0.0;
        _tableView.hidden=YES;
    } completion:^(BOOL finished) {

        [self removeFromSuperview];
        [_tableView removeFromSuperview];
    }];

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titles.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.backgroundColor=[UIColor clearColor];
    cell.textLabel.text=[_titles objectAtIndex:indexPath.row];
    cell.textLabel.textColor=[UIColor whiteColor];
    cell.textLabel.font=[UIFont systemFontOfSize:];
    cell.textLabel.textAlignment=NSTextAlignmentCenter;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ) {
        ;
    }
    return tableView.frame.size.height/_titles.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _selectMallMoreMenu(indexPath.row);
    [self dismissView];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

#ifdef __IPHONE_8_0
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
#endif
}

@end
-(void)popMallMoreView:(id)sender
{
    mallMoreView *moreView=[mallMoreView sharedManager];
    moreView.tableView=[[UITableView alloc]init];
    moreView.tableView.frame=CGRectMake(MAINWIDTH-, , , );
    moreView.titles=@[@"回到首页",@"闪购订单",@"收货地址"];
    moreView.selectMallMoreMenu=^(NSInteger index)
    {
        NSLog(@"%ld",index);
    };
    [moreView showInView:self.view];

}

最新文章

  1. mongodb 数据库查询
  2. 一个 -100.01 的double 在内存中怎么存储的. 一个中文String 在内存中占多少直接 utf-8 / GBK
  3. Java多线程(转)
  4. C# 如何实现带消息数的App图标
  5. dos2unix用法
  6. CentOS(十)--与Linux文件和目录管理相关的一些重要命令②
  7. visual studio 2012更换皮肤、功能添加
  8. 【转】javascript日期操作详解(脚本之家整理)
  9. ROS的文件系统
  10. hello world2
  11. sklearn:最近邻搜索sklearn.neighbors
  12. 3#Java案例
  13. C#模拟客户端发送数据示例
  14. Unity之配置转换工具
  15. 【第五篇】SAP ABAP7.5x新语法之命名规约
  16. 关于SqlBulkCopy SQL批量导入需要注意,列名是区分大小写的
  17. 绝对定位多个字居中显示的css
  18. gradle 错误
  19. jQuery on() 方法问题
  20. python 全栈开发:str(字符串)常用方法操作 、for 有限循环以及if 循环

热门文章

  1. @componentscan注解的用法和作用
  2. 【cocos2d-x 手游研发小技巧(5)获取网络图片缓存并展示】
  3. jQuery--事件, 事件绑定, 阻止事件冒泡, 事件委托,页面载入后函数
  4. java学习笔记—第三方操作数据库包专门接收DataSource-dbutils (30)
  5. Java-File类获取目录下文件名-遍历目录file.listFiles
  6. 【文文殿下】Manache算法-学习笔记
  7. 查看npm安装包版本
  8. django入门-模型-part2
  9. httpclient4.5 https请求 忽略身份验证
  10. [Swift]遍历集合类型(数组、集合和字典)