turnView

  • 前言:
    • 看这个简单demo你可以学到很多东西。

涉及导航栏随着tableView滑动是否隐藏,随着tableView的滑动让TabBar隐藏,停止滑动显示TabBar。还有NavigationController的titleView动态缩放效果,还还还加了UITableView分区展开与收起。
虽然没有很详细的介绍每一个步骤,不过大家应该都看的懂,看不懂的可以联系我

先看一下简单的效果:

Turning.gif

代码:

//  ViewController.m
//  turnView
//
//  Created by ming on 16/5/28.
//  Copyright © 2016年 ming. All rights reserved.


#import "ViewController.h"

#define MGSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define MGSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

@interface ViewController ()

@end

@implementation ViewController
{
    UISegmentedControl *segment;
    UIView *_leftView;
    UIView *_rightnView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setMainView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setMainView{
    UINavigationBar *navBar = [UINavigationBar appearance];
    navBar.barTintColor = [UIColor purpleColor];
    navBar.tintColor = [UIColor colorWithRed:0.8 green:0.5 blue:1 alpha:1.000];
    navBar.translucent = NO;
    
    NSArray *segArr=@[@"订单",@"商品"];
    //设置segment
    segment=[[UISegmentedControl alloc] initWithItems:segArr];
    segment.frame=CGRectMake(MGSCREEN_WIDTH/2-266/4, 7, 266/2, 30);
    [segment addTarget:self action:@selector(selectIndex:) forControlEvents:(UIControlEventValueChanged)];
    segment.layer.borderColor=[UIColor whiteColor].CGColor;
    segment.tintColor=[UIColor orangeColor];
    NSDictionary *dics = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15.0f] forKey:NSFontAttributeName];
    [segment setTitleTextAttributes:dics forState:UIControlStateNormal];
    segment.selectedSegmentIndex = 0;
    [self.navigationController.navigationBar addSubview:segment];
    
    _leftView=[[UIView alloc] initWithFrame:(CGRectMake(0, 64, MGSCREEN_WIDTH, MGSCREEN_HEIGHT-64))];
    _leftView.backgroundColor=[UIColor redColor];
    [self.view addSubview:_leftView];
    
    _rightnView=[[UIView alloc] initWithFrame:(CGRectMake(0, 64, MGSCREEN_WIDTH, MGSCREEN_HEIGHT-64))];
    _rightnView.backgroundColor=[UIColor greenColor];
    [self.view addSubview:_rightnView];
    
    [self.view bringSubviewToFront:_leftView];
}

- (void)selectIndex:(UISegmentedControl *)segmentor{
    if(segmentor.selectedSegmentIndex==0){
        
        [self animationWithView:self.view WithAnimationTransition:(UIViewAnimationTransitionFlipFromLeft)];
        [self.view bringSubviewToFront:_leftView];
        
    }else{
        [self animationWithView:self.view WithAnimationTransition:(UIViewAnimationTransitionFlipFromRight)];
        [self.view bringSubviewToFront:_rightnView];
    }
}

- (void) animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition) transition
{
    [UIView animateWithDuration:0.5f animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationTransition:transition forView:view cache:YES];
    }];
}

@end



升级版

给Tabbar 加了动画(拖动tableView的时候会隐藏,不拖拽会显示)
也对cell 加了动画处理(cell显示的时候会有动画效果)
导航栏的渐变效果

  • 先看一下升级的效果:


    turnView.gif
#import "ViewController.h"

#define MGSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define MGSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UISegmentedControl *segment;
    UITableView *_leftView;
    UITableView *_rightnView;
    UIView *_topBgView;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setMainView];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden=YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setMainView{
    
//    UINavigationBar *navBar = [UINavigationBar appearance];
//    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
//    if(ISIOS8)
//        navBar.translucent = NO;
//    else
//        self.navigationBar.translucent  =NO;
//    navBar.barTintColor = naBarTiniColor;
//    navBar.tintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1.000];
//    [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//    
//    [navBar setTitleTextAttributes:@{
//                                     NSForegroundColorAttributeName :[UIColor whiteColor] ,
//                                     NSFontAttributeName : [UIFont boldSystemFontOfSize:18]
//                                     }];
//    
//    
//    if(barItem==self.navigationItem.leftBarButtonItem){
//        [barItem setTitleTextAttributes:@{
//                                          NSForegroundColorAttributeName : [UIColor clearColor],
//                                          NSFontAttributeName : [UIFont systemFontOfSize:0]
//                                          } forState:UIControlStateNormal];
//    }else{
//        [barItem setTitleTextAttributes:@{
//                                          NSForegroundColorAttributeName : [UIColor whiteColor],
//                                          NSFontAttributeName : [UIFont systemFontOfSize:13]
//                                          } forState:UIControlStateNormal];
//        
//    }
    
//    UINavigationBar *navBar = [UINavigationBar appearance];
   
//    navBar.backgroundColor = [UIColor blueColor];
//    navBar.barTintColor = [UIColor purpleColor];
//    navBar.tintColor = [UIColor colorWithRed:0.8 green:0.5 blue:1 alpha:1.000];
//    navBar.translucent = NO;
//    [navBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    
    _leftView=[[UITableView alloc] initWithFrame:(CGRectMake(0, 64, MGSCREEN_WIDTH, MGSCREEN_HEIGHT-64))];
    _leftView.delegate = self;
    _leftView.dataSource = self;
    _leftView.backgroundColor=[UIColor redColor];
    [self.view addSubview:_leftView];
    
    _rightnView=[[UITableView alloc] initWithFrame:(CGRectMake(0, 64, MGSCREEN_WIDTH, MGSCREEN_HEIGHT-64))];
    _rightnView.backgroundColor=[UIColor greenColor];
    [self.view addSubview:_rightnView];

    _topBgView=[[UIView alloc] initWithFrame:(CGRectMake(0, 0, MGSCREEN_WIDTH, 64))];
//    _topBgView.alpha = 0.0f;
    [self.view addSubview:_topBgView];
    
    NSArray *segArr=@[@"订单",@"商品"];
    //设置segment
    segment=[[UISegmentedControl alloc] initWithItems:segArr];
    segment.frame=CGRectMake(MGSCREEN_WIDTH/2-266/4, 25, 266/2, 30);
    [segment addTarget:self action:@selector(selectIndex:) forControlEvents:(UIControlEventValueChanged)];
    segment.layer.borderColor=[UIColor whiteColor].CGColor;
    segment.tintColor=[UIColor orangeColor];
    NSDictionary *dics = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15.0f] forKey:NSFontAttributeName];
    [segment setTitleTextAttributes:dics forState:UIControlStateNormal];
    segment.selectedSegmentIndex = 0;
    [self.view insertSubview:segment aboveSubview:_topBgView];
    
    [self.view bringSubviewToFront:_leftView];
}

#pragma mark - segment的target
- (void)selectIndex:(UISegmentedControl *)segmentor{
    if(segmentor.selectedSegmentIndex==0){
        
        [self animationWithView:self.view WithAnimationTransition:(UIViewAnimationTransitionFlipFromLeft)];
        [self.view bringSubviewToFront:_leftView];
        
    }else{
        [self animationWithView:self.view WithAnimationTransition:(UIViewAnimationTransitionFlipFromRight)];
        [self.view bringSubviewToFront:_rightnView];
    }
}

#pragma mark - 翻转动画
- (void) animationWithView:(UIView *)view WithAnimationTransition:(UIViewAnimationTransition) transition
{
    [UIView animateWithDuration:0.5f animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationTransition:transition forView:view cache:YES];
    }];
}

#pragma mark - scrollView代理
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    [UIView animateWithDuration:1 animations:^{
 //  给Tabbar 加入动画       self.tabBarController.tabBar.transform = CGAffineTransformMakeTranslation(0, 49);
    }];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    UIColor *color = [UIColor brownColor];
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY > 0) {
        CGFloat alpha = 1 - ((64 - offsetY) / 64);
        if (alpha>1) {
            alpha = 1;
        }
        _topBgView.backgroundColor = [color colorWithAlphaComponent:alpha];
    } else {
        _topBgView.backgroundColor = [color colorWithAlphaComponent:0];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    [UIView animateWithDuration:1.0 delay:0.8 options:UIViewAnimationOptionOverrideInheritedCurve animations:^{
        self.tabBarController.tabBar.transform = CGAffineTransformIdentity;
    } completion:nil];
}

#pragma mark - 数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"ming-%ld",indexPath.row];
    return  cell;
}

#pragma mark - 代理
/**
 *   添加cell滚动的动画
 */
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    // 防止重复添加动画
    [cell.layer removeAnimationForKey:@"ming"];
    CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.y"];
    keyframeAnimation.values = @[@(-2),@(-1),@(1),@(2)];
    keyframeAnimation.duration = 0.3;
    [cell.layer addAnimation:keyframeAnimation forKey:@"ming"];
}


@end




  • 升升升升升级版

首先加了iOS 实现NavigationController的titleView动态缩放效果,还加了UITableView分区展开与收起

  • 再看升升升升升级版的效果:


    升级版.gif

觉得不错给个赞,Thanks

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 198,932评论 5 466
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,554评论 2 375
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 145,894评论 0 328
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,442评论 1 268
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,347评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,899评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,325评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,980评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,196评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,163评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,085评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,826评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,389评论 3 302
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,501评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,753评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,171评论 2 344
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,616评论 2 339

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 11,972评论 4 60
  • 转载自:https://github.com/Tim9Liu9/TimLiu-iOS 目录 UI下拉刷新模糊效果A...
    袁俊亮技术博客阅读 11,899评论 9 105
  • 初秋夜渐凉, 独卧明月床, 若有青丝在, 何必勇称王。
    柴狗李小白阅读 254评论 0 2
  • 夏季养生杂谈 夏天,天气炎热,人们不仅易发肠道疾病,有时还会浑身乏力、食欲不振等状况。那么怎样改善这种状况呢?感兴...
    勤录阅读 272评论 0 0