一,效果图。

二,工程图。

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>
#import "SVSegmentedControl.h" @interface RootViewController : UIViewController
<UIScrollViewDelegate>
{
UIScrollView *scrollView1;
UIScrollView *scrollView2;
UIPageControl *pag;
NSMutableArray *dataArray;
SVSegmentedControl *options;
} @end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //初始化背景图
[self initBackGroundView];
}
#pragma -mark -functions
-(void)initBackGroundView
{
//隐藏导航条
self.navigationController.navigationBarHidden=YES; //底部的滚动条
scrollView1=[[UIScrollView alloc]init];
scrollView1.frame=CGRectMake(0, 40, 320, 400);
scrollView1.backgroundColor=[UIColor grayColor];
scrollView1.delegate=self;
scrollView1.pagingEnabled=YES;
scrollView1.contentSize=CGSizeMake(320*2, 376);
[self.view addSubview:scrollView1]; //第一页的内容
UIView *v1=[[UIView alloc]init];
[v1 setFrame:CGRectMake(0, 0, 320, 376)];
v1.backgroundColor=[UIColor redColor];
[scrollView1 addSubview:v1]; //第二页的内容
UIView *v2=[[UIView alloc]init];
v2.frame=CGRectMake(320, 0, 320, 376);
v2.backgroundColor=[UIColor blueColor];
[scrollView1 addSubview:v2]; //下面指示页的圆点
pag=[[UIPageControl alloc]initWithFrame:CGRectMake(160, 400, 0, 0)];
pag.numberOfPages=2;
pag.currentPage=0;
[self.view addSubview:pag]; //上面的滑动图标
options = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"购车应用",@"车主应用", nil]];
[options addTarget:self action:@selector(actiBtClick:) forControlEvents:UIControlEventValueChanged];
[options setBackgroundImage:[UIImage imageNamed:@"switchBg.png"]];
options.center=CGPointMake(160, 50);
options.crossFadeLabelsOnDrag=YES;
options.selectedIndex=0;
options.textColor=[UIColor blackColor];
options.LKWidth=120;
options.textShadowOffset=CGSizeMake(0, 0);
options.textShadowColor=[UIColor clearColor];
options.height=30;
options.thumb.backgroundImage=[UIImage imageNamed:@"按钮-2.png"];
options.thumb.highlightedBackgroundImage=[UIImage imageNamed:@"按钮-2.png"];
options.thumb.textShadowColor=[UIColor clearColor];
options.thumb.textShadowOffset=CGSizeMake(0, 0);
[self.view addSubview:options]; }
#pragma -mark -doClickActions
- (void)actiBtClick:(SVSegmentedControl *)sender
{
if(sender.selectedIndex==0)
{
[scrollView1 setContentOffset:CGPointMake(0, scrollView1.contentOffset.y) animated:YES];
pag.currentPage=0;
}
else if(sender.selectedIndex==1)
{
[scrollView1 setContentOffset:CGPointMake(320, scrollView1.contentOffset.y) animated:YES];
pag.currentPage=1;
}
}
#pragma -mark -scrollViewDelegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if(scrollView1.contentOffset.x==0)
{
pag.currentPage=0;
[options moveThumbToIndex:0 animate:YES];
}
else if(scrollView1.contentOffset.x==320)
{
pag.currentPage=1;
[options moveThumbToIndex:1 animate:YES];
}
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

【代码笔记】iOS-底下滚动,上面标题栏也会跟着变动的更多相关文章

  1. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  2. IOS在滚动的时候fixed消失

      前段时间,除了apple发布了新的硬件之外,同步还发布了新的操作系统,IOS11,当大家都将注意力聚焦在那个奇怪的刘海该如何适配的时候,笔者的项目在适配IOS11却出现了其他的问题. 众所周知,I ...

  3. 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程

    一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...

  4. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

  5. iOS 字体滚动效果 ScrollLabel

    写了一个简单的字体滚动效果. 用了一种取巧的方式,传入两个一摸一样的Label(当然也可以是别的视图), 话不多说,代码里面讲解. SEScrollLabel.h #import <UIKit/ ...

  6. 【Hadoop代码笔记】目录

    整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...

  7. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  8. jquery图片无缝滚动代码左右 上下无缝滚动图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Jquery几行代码解决跟随屏幕滚动DIV

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. CSS魔法堂:重新认识Box Model、IFC、BFC和Collapsing margins

    前言   盒子模型作为CSS基础中的基础,曾一度以为掌握了IE和W3C标准下的块级盒子模型即可,但近日在学习行级盒子模型时发现原来当初是如此幼稚可笑.本文尝试全面叙述块级.行级盒子模型的特性.作为近日 ...

  2. bash魔法堂:History用法详解

    Brief 又要敲那条长到没朋友的命令了,真心不再爱了... 有了history这条命令我想大家可以再爱一次了吧! >history 语法: history [n | -c | -raw his ...

  3. 搭建CnetOS6.5x64最小系统及在线yum源的配置

    CentOS系统作为红帽系列的一款linux系统,因为其免费.开源,在中小企业中得到了广泛应用,生产上为了更好的利用资源,都采用最小系统安装,因为一个图形界面都会占去系统资源的30%到40%,生产上一 ...

  4. swift3.0的改变

    Swift在这2年的时间内,发展势头迅猛,在它开源后,更是如井喷一样,除了 iOS.mac 平台,还支持了 Linux. 而今年下半年, Swift 3.0 也会随之发布.https://github ...

  5. 【Swift学习】Swift编程之旅---集合类型之Sets(七)

    Sets是存储无序的相同类型的值,你可以在顺序不重要的情况下使用Sets来替代数组,或者当你需要同一个值在集合中只出现一次时. 一.Sets类型语法  写作Set<Element>,Ele ...

  6. Android Studio快捷键每日一练(4)

    原文地址:http://www.developerphil.com/android-studio-tips-of-the-day-roundup-4/ 33.分析数据流到当前位置 苹果/Windows ...

  7. MVC中几种常用ActionResult

    一.定义 MVC中ActionResult是Action的返回结果.ActionResult 有多个派生类,每个子类功能均不同,并不是所有的子类都需要返回视图View,有些直接返回流,有些返回字符串等 ...

  8. pm2 配置

    ---恢复内容开始--- 1. ecosystem.json { "apps": [ { "name": "name", // 项目名 &q ...

  9. 初学C++之自定义类型名简化

    说明:本人使用的是vc++ IDE:vs2013 我在自定义一些类时,有时会取一些很长的名字,但是这不利于使用,这个时候就可以使用类型名简化. class MathAddBBBB { }; using ...

  10. Mac上安装go环境

    Mac 安装 GO语言开发环境 官网:https://golang.org/ go语言的安装:http://docscn.studygolang.com/doc/install 下载:go1.7rc3 ...