zoukankan      html  css  js  c++  java
  • tableView等滚动视图滚动时收缩上下导航栏与标签栏

    代码如下,今天有点忙,不想细说了,看不明白可以联系我

    //
    //  LQXViewController.m
    //  LQXCallBackBar
    //
    //  Created by 刘祺旭 on 15/4/27.
    //  Copyright (c) 2015年 CSDN探花花花. All rights reserved.
    //
    
    #import "LQXViewController.h"
    #define LQXWidth self.view.bounds.size.width
    #define LQXHeight self.view.bounds.size.height
    #define LQXData [NSString stringWithFormat:@"随机数据---%d", arc4random_uniform(1000000)]
    
    @interface LQXViewController ()<UITableViewDelegate,UITableViewDataSource>
    @property (nonatomic, strong)UITableView *tableView;
    @property (nonatomic, strong)NSMutableArray *dataArray;
    @property (nonatomic, assign) BOOL hidden;
    @property (nonatomic, assign) BOOL scrollUporDown;
    @end
    
    @implementation LQXViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.tabBarController.tabBar.frame = CGRectMake(0, LQXHeight - 40, LQXWidth, 40);
        UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, LQXWidth, 20)];
        
        statusBarView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"首页--标题栏.png"]];
        
        [self.view addSubview:statusBarView];
        
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
        
        
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, LQXWidth, LQXHeight - 20) style:0];
        self.tableView.bounces = YES
        ;
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        self.tableView.rowHeight = 135;
        self.tableView.userInteractionEnabled = YES;
        self.tableView.showsHorizontalScrollIndicator = NO;
        self.tableView.showsVerticalScrollIndicator = NO;
        self.dataArray = [NSMutableArray array];
        for (int i = 0; i< 100; i++) {
            [self.dataArray addObject:LQXData];
        }
        [self.view addSubview:self.tableView];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    #pragma mark - Table view data source
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return self.dataArray.count;
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *str = @"reuse";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:str];
        }
        cell.textLabel.text = self.dataArray[indexPath.row];
        return cell;
        
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
        if ([scrollView isEqual:self.tableView]) {
            static float newy = 0;
            static float oldy = 0;
            newy = scrollView.contentOffset.y ;
            if (newy != oldy ) {
                if (newy > oldy) {
                    self.scrollUporDown = YES;
                }else if(newy < oldy){
                    self.scrollUporDown = NO;
                }
                oldy = newy;
            }
            if (_scrollUporDown == YES) {
                self.hidden = YES;
                [UIView animateWithDuration:0.5 animations:^{
                    self.navigationController.navigationBar.frame = CGRectMake(0, -40, LQXWidth, 40);
                    self.tabBarController.tabBar.frame = CGRectMake(0 , LQXHeight + 40, LQXWidth, 40);
                }];
                
            }
            else if (_scrollUporDown == NO) {
                if (self.hidden == YES) {
                    [UIView animateWithDuration:0.5 animations:^{
                        self.navigationController.navigationBar.frame = CGRectMake(0, 20, LQXWidth, 40);
                        self.tabBarController.tabBar.frame = CGRectMake(0 , LQXHeight , LQXWidth, 40);
                    }];
                    
                    
                    self.hidden = NO;
                }
            }
            
        }
    }
    
    /*
    #pragma mark - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */
    
    @end
    



  • 相关阅读:
    String驻留带来的危害
    Go语言的堆栈分析
    SecureCRT使用技巧
    Javascript中相同Function使用多个名称
    记录Office Add-in开发经验
    Silverlight和WPF中DataContractJsonSerializer对时间的处理差异
    ASP.NET MVC项目实践技巧
    有点担心Node.js的未来了
    回首经典的SQL Server 2005
    duilib关于学习Demo中的QQ
  • 原文地址:https://www.cnblogs.com/liuqixu/p/4683207.html
Copyright © 2011-2022 走看看