一,效果图。

二,工程图。

三,代码。

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. python生成随机密码

    有时候我们会想生成一个随机密码,这样我们通过Python中的一些随机方法,就可生成我们任意长度和复杂度的密码,代码如下: # -*- coding=utf-8 -*- import random im ...

  2. 【转载】CSS Sticky Footer: 完美的CSS绝对底部

    下面是我找到的一个比较完美的方法,来自国外的设计达人,纯CSS,可以实现: 当正文内容很少时,底部位于窗口最下面.当改变窗口高度时,不会出现重叠问题. <div id="wrap&qu ...

  3. jQuery动态设置样式List item

    前段时间,Insus.NET有修改一个功能<激活当前视图菜单高亮呈现>http://www.cnblogs.com/insus/p/5287093.html 今天Insus.NET想改用另 ...

  4. WinPhone学习笔记(二)——页面外观剖析

    上一个篇博文说了WinPhone页面内部的东西,现在介绍表面的东西,先来看看一下一个WinPhone页面 这个页面分了三部分:顶部这个是状态栏, 中间这个是一个页面的内容部分, 最下面则是应用程序栏 ...

  5. C#获取 URL参数

    假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www.te ...

  6. SQL内部拼接执行SQL语句时,实现变量参数化

    exec sp_ExecuteSql执行的SQL语句拼接起是比较麻烦,如果关联的表多拼接过程是很容易出错的,下面这方法非常的好用,而且简单直观 if exists(select * from syso ...

  7. 第 28 章 CSS3 多列布局

    学习要点: 1.早期多列问题 2.属性及版本 3.属性解释 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 提供的多列布局,通过多列布局我们方便的创建流体的多列布局. 一.早期多列问题 我们 ...

  8. Code First :使用Entity. Framework编程(4) ----转发 收藏

    第4章 对关系使用默认规则与配置 在第3章,你已经掌握了默认规则与配置对属性以及其在数据库映射的字段的影响.在本章,我们把焦点放在类之间的关系上面.这包括类在内存如何关联,还有数据库中的外键维持等.你 ...

  9. jQuery实现购物车多物品数量的加减+总价计算

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

  10. 每日一博 | 用 Ionic2 创建 App 启动页滑动欢迎界面

    原文  https://my.oschina.net/qinphil/blog/777787 效果如下,图片来自网络 本文例子和上图稍有不同,主要功能如下: 每滑动一下展示一张全屏图片: 滑动到最后一 ...