【代码笔记】iOS-底下滚动,上面标题栏也会跟着变动
一,效果图。

二,工程图。

三,代码。
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-底下滚动,上面标题栏也会跟着变动的更多相关文章
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- IOS在滚动的时候fixed消失
前段时间,除了apple发布了新的硬件之外,同步还发布了新的操作系统,IOS11,当大家都将注意力聚焦在那个奇怪的刘海该如何适配的时候,笔者的项目在适配IOS11却出现了其他的问题. 众所周知,I ...
- 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程
一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...
- 【hadoop代码笔记】hadoop作业提交之汇总
一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...
- iOS 字体滚动效果 ScrollLabel
写了一个简单的字体滚动效果. 用了一种取巧的方式,传入两个一摸一样的Label(当然也可以是别的视图), 话不多说,代码里面讲解. SEScrollLabel.h #import <UIKit/ ...
- 【Hadoop代码笔记】目录
整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- jquery图片无缝滚动代码左右 上下无缝滚动图片
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Jquery几行代码解决跟随屏幕滚动DIV
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- HT for Web 中Painter的介绍及用法
鉴于许多同学对Painter不熟悉,所以撰写此文介绍下.Painter的中文意思是画家.漆工,那放到HT里是什么意思呢?很简单,这是HT特有的一种接口,允许开发者在拓扑及其它通用组件上使用Canvas ...
- Ionic2学习笔记(4):*号
作者:Grey 原文地址: http://www.cnblogs.com/greyzeng/p/5544479.html 大家常常会在ionic2页面中见到*号 ...
- Emit学习(3) - OpCodes - 循环和异常
本来准备直接进入Dapper的, 但是昨天初步看了一下, 内容不少, Dapper不愧是一款成熟的框架, 里面对各种情况的考虑, 很实用, 不过这也使得我短时间内看不完, 所以得等几天了. 那就先来看 ...
- ab网站压力测试
ab网站压力测试命令的参数.输出结果的中文注解 permalink 以前安装好APACHE总是不知道该如何测试APACHE的性能,现在总算找到一个测试工具了.就是APACHE自带的测试工具AB( ...
- 从vs2010的UnitTestFramework类库提取私有方法反射调用的方法
背景 年龄大点的程序员都知道在vs2010中创建单元测试非常的简单,鼠标定位在方法名字,右键创建单元测试,就会创建一个测试方法,即使是在私有方法上也可以创建测试方法. VS2010以后就没这么简单了, ...
- 第二讲:WCF介绍(2)
代码 https://yunpan.cn/cPns5DkGnRGNs 密码:3913 在上一讲中我们说到 在代码 当中 完成了 服务的寄宿. 这里我们说下 在实际的开发 当中 我们一般不会去 ...
- 孙鑫MFC学习笔记17:进程间通信
17 1.进程间通信4种方式 2.OpenClipboard打开剪贴板 3.EmptyClipboard清空剪贴板,并把所有权分配给打开剪贴板的窗口 4.SetClipboardData设置剪贴板数据 ...
- jquery的ajax可以传入的三种参数类型
在jquery的ajax函数中,可以传入3种类型的数据 1.文本:"uname=alice&mobileIpt=110&birthday=1983-05-12" 2 ...
- Java_Class 16方格拼图游戏
public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Game ...
- GIT 查看/修改用户名和邮箱地址
用户名和邮箱地址的作用用户名和邮箱地址是本地git客户端的一个变量,不随git库而改变.每次commit都会用用户名和邮箱纪录.github的contributions统计就是按邮箱来统计的.查看用户 ...