美文网首页
导航条的下拉动画

导航条的下拉动画

作者: Areyouhere | 来源:发表于2017-03-13 09:30 被阅读0次
#import "WatchViewController.h"
#import "HJHPullDownView.h"

@interface WatchViewController ()
@property (nonatomic ,weak) HJHPullDownView *pullDownView;
@property (nonatomic ,assign) BOOL isPop;
@end

@implementation WatchViewController
- (HJHPullDownView *)pullDownView
{
    if (!_pullDownView)
    {
        _pullDownView = [HJHPullDownView showInView:self.view WithItems:@[@"1",@"2",@"3",@"4",@"5",@"6"] WithOriY:64];
    }
    return _pullDownView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"下拉" style:UIBarButtonItemStylePlain target:self action:@selector(pullDown)];
}
- (void)pullDown
{
    if (_isPop == NO)
    {
        [self pullDownView];
        
    }
    else
    {
        [self.pullDownView hide];
    }
    _isPop = !_isPop;
}
@end

自定义 下拉菜单

#import <UIKit/UIKit.h>

@interface HJHPullDownView : UIView

+ (instancetype)showInView:(UIView*)superView WithItems:(NSArray *)items WithOriY:(CGFloat)oriY;

- (void)hide;
@end
#import "HJHPullDownView.h"

// 每行几个模型
#define HJHCols 3

@interface HJHPullDownView ()
// items 模型数组
@property (nonatomic ,strong) NSArray *items;

@property (nonatomic ,strong) NSMutableArray *btns;
@end

@implementation HJHPullDownView
- (NSMutableArray *)btns
{
    if (!_btns)
    {
        _btns = [NSMutableArray array];
    }
    return _btns;
}
- (void)hide
{
    [UIView animateWithDuration:0.5 animations:^{
        self.transform = CGAffineTransformMakeTranslation(0, -self.bounds.size.height);
    } completion:^(BOOL finished) {
       [self removeFromSuperview];
    }];
}
+ (instancetype)showInView:(UIView*)superView WithItems:(NSArray *)items WithOriY:(CGFloat)oriY
{
    NSUInteger count = items.count;
    // 看看items  是不是3的倍数
    if (count % 3 != 0)
    {
        // 抛出异常
       NSException *excp = [NSException exceptionWithName:@"总数不符" reason:@"传入的数组总数必须是3的倍数" userInfo:nil];
        [excp raise];
    
    }
    
    NSUInteger rows = (count - 1) / HJHCols + 1;
    CGFloat itemWH = Screen_Width / HJHCols;
    CGFloat menmuH = rows * itemWH;
    
    HJHPullDownView * menu = [[HJHPullDownView alloc]initWithFrame:CGRectMake(0, oriY, Screen_Width, menmuH)];
    menu.items = items;
    [menu setUpAllBtns];
    [menu setUpAllDivideView];
    menu.backgroundColor = [UIColor blackColor];
    
    
    UIView *blackView = [[UIView alloc]initWithFrame:menu.frame];
    blackView.backgroundColor = [UIColor blackColor];
    [superView addSubview:blackView];
    
#warning 动画
    menu.transform = CGAffineTransformMakeTranslation(0, -menu.bounds.size.height);
    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        
        menu.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        
        [blackView removeFromSuperview];
    }];
    
    [superView addSubview:menu];
    
    return menu;
}
- (void)setUpAllBtns
{
    for (NSString * str in self.items)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [btn setTitle:str forState:UIControlStateNormal];
        
        [self addSubview:btn];
        [self.btns addObject:btn];
    }
}
- (void)setUpAllDivideView
{
    CGFloat itemWH = Screen_Width / HJHCols;
    // 竖 总列数 - 1
    for (int i = 0; i < HJHCols - 1; i++)
    {
        UIView *divideV = [[UIView alloc]init];
        divideV.backgroundColor = [UIColor whiteColor];
        divideV.frame = CGRectMake((i+1) * itemWH, 0, 1, self.bounds.size.height);
        [self addSubview:divideV];
    }
    NSUInteger rows = (self.items.count - 1) / HJHCols +1;
    // 横 总行数 - 1
    for (int i = 0; i < rows - 1; i++)
    {
        UIView *divideV = [[UIView alloc]init];
        divideV.backgroundColor = [UIColor whiteColor];
        divideV.frame = CGRectMake(0, (i+1) * itemWH,self.bounds.size.width,1 );
        [self addSubview:divideV];
    }
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    //布局所有的按钮
    NSUInteger count = self.items.count;
    NSUInteger col = 0;
    NSUInteger row = 0;
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat itemWH = Screen_Width / HJHCols;
    
    for (NSUInteger i =0; i<count; i++)
    {
        col = i % HJHCols;
        row = i / HJHCols;
        UIButton *btn = self.btns[i];
        
        x = col * itemWH;
        y = row * itemWH;
        
        btn.frame = CGRectMake(x, y, itemWH, itemWH);
        
        
    }
}
@end

973B27C2-DAD4-4D81-9C90-F0EB84C68718.png 46246F02-B651-4094-BBFB-4C93C3FA1509.png

相关文章

  • 导航条的下拉动画

    自定义 下拉菜单

  • jQuery 实现水平菜单下拉功能

    写一个横向导航条 在导航条的每个块里面添加下拉文本 下拉内容display:none; slideDown/sli...

  • Bootstrap3-导航条

    1. 定义导航条 添加网站表示名(navbar-brand) 导航条包括链接、下拉菜单、网站标题和折叠按钮 2. ...

  • iOS用Sketch制作APP下拉刷新的GIF动画

    iOS用Sketch制作APP下拉刷新的GIF动画 iOS用Sketch制作APP下拉刷新的GIF动画

  • Bootstrap

    Bootstrap的导航条下拉菜单为了适应移动设备没有鼠标hover的状态,都是点击弹出下拉菜单,为了适应一般网站...

  • Bootstrap

    表格: 响应式布局 下拉菜单: 表单: 导航: 02导航条:navbar 03: 完成品: NEW JavaScr...

  • MJRefresh下拉刷新上拉加载自定义

    下拉刷新 下拉刷新 默认 下拉刷新 动画图片 JRGifHeader.h JRGifHeader.m 下拉刷新 隐...

  • 一些常用动画

    旋转动画——loading 下拉效果

  • iOS下拉动画:仿华尔街见闻

    简介 最近看到华尔街见闻下拉刷新动画,觉得挺好看的。于是决定模仿写一个demo,顺便发现华尔街见闻下拉刷新动画的1...

  • MJRefresh用法详解

    下拉刷新01-默认 下拉刷新02-动画图片 下拉刷新04-隐藏状态和时间 下拉刷新05-自定义文字 下拉刷新06-...

网友评论

      本文标题:导航条的下拉动画

      本文链接:https://www.haomeiwen.com/subject/dkkfnttx.html