【代码笔记】iOS-两个滚动条,上下都能滑动
一,效果图。
二,工程图。
三,代码。
RootViewController.h
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController
<UIScrollViewDelegate>
{
UIView *backView;
UIScrollView *scrollerViewFirst;
UIScrollView *scrollerViewSecond;
UIImageView * imageViewBook;
UILabel *label;
UIImageView *bigImageView;
UIView *bigView;
} @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 -funcitons
-(void)initBackgroundView
{
//放大的时候,底部的图
bigView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 440)];
[self.view addSubview:bigView]; //背景图
backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:backView]; //背景
UIImageView * imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"backImage.png"]];
imageView.frame = CGRectMake(0, 0, 320, 460);
[backView addSubview:imageView]; //scrollerViewFrist
scrollerViewFirst = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 151)];
scrollerViewFirst.contentSize = CGSizeMake(320 * 4, 151);
scrollerViewFirst.contentOffset = CGPointMake(0, 0);
scrollerViewFirst.bounces = YES;
scrollerViewFirst.alwaysBounceHorizontal = YES;
scrollerViewFirst.showsHorizontalScrollIndicator = NO;
scrollerViewFirst.pagingEnabled =YES;
scrollerViewFirst.delegate = self;
scrollerViewFirst.tag=1;
scrollerViewFirst.backgroundColor=[UIColor redColor];
[backView addSubview:scrollerViewFirst]; //scrollerViewSecond
scrollerViewSecond = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 152, 320, 308)];
scrollerViewSecond.contentSize = CGSizeMake(320 * 4, 308);
scrollerViewSecond.contentOffset = CGPointMake(0, 0);
scrollerViewSecond.bounces = YES;
scrollerViewSecond.alwaysBounceHorizontal = YES;
scrollerViewSecond.showsHorizontalScrollIndicator = YES;
scrollerViewSecond.delegate = self;
scrollerViewSecond.pagingEnabled =YES;
scrollerViewSecond.backgroundColor=[UIColor orangeColor];
[backView addSubview:scrollerViewSecond]; //scrollerFirst的大的背景图
for (int i = 0; i < 4;i++) {
for ( int j = 0; j < 3; j++) {
UIImageView * imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"scrollerFirstTop.png"]]];
imageview.frame = CGRectMake(0 + i* 320, 0, 320, 151);
[scrollerViewFirst addSubview:imageview];
}
} //scrollerFirst书架上的图集
for ( int i = 0; i < 12; i++) { imageViewBook = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i+1]]];
imageViewBook.contentMode = UIViewContentModeScaleToFill;
imageViewBook.frame = CGRectMake((10 + i * 106 ) , 22, 80, 100);
imageViewBook.userInteractionEnabled = YES;
imageViewBook.tag = i; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doClickTapGesture:)];
[imageViewBook addGestureRecognizer:tapGesture]; [scrollerViewFirst addSubview:imageViewBook];
} //scrollerSecond的标题
for (int i = 0; i < 4; i++) { UIImageView *topImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"scrollerSecondTop"]];
topImageView.frame = CGRectMake(100 + 320 *i , -40 , 220, 100);
[scrollerViewSecond addSubview:topImageView]; UIImageView *titleImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"scrollerSecondTitle.png"]];
titleImageView.frame = CGRectMake(3 + 320 *i, 20, 100, 55);
[scrollerViewSecond addSubview:titleImageView];
} //scrollerViewSecond每个里面的线
for (int i = 0; i < 4;i++) {
for ( int j = 0; j < 3; j++) {
label = [[UILabel alloc]initWithFrame:CGRectMake(320*i , 80 + 60 *j, 320, 20)];
if (i==0) {
label.backgroundColor=[UIColor redColor];
}else if (i==1){
label.backgroundColor=[UIColor greenColor];
}else if (i==2){
label.backgroundColor=[UIColor blackColor];
}else if (i==3){
label.backgroundColor=[UIColor blueColor];
}
[label setFont:[UIFont systemFontOfSize:12]];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blueColor];
[scrollerViewSecond addSubview:label]; }
} }
#pragma -mark -doClickAction
-(void)doClickTapGesture:(UITapGestureRecognizer *)tapGesture
{
NSLog(@"doClickTapGesture"); //一个页面从右侧翻转过来的效果
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[UIView commitAnimations]; bigImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",tapGesture.view.tag +1]]];
bigImageView.frame = CGRectMake(0,0,300, 440);
bigImageView.userInteractionEnabled = YES; UITapGestureRecognizer * tgrBig = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(beginSmall:)];
[bigImageView addGestureRecognizer:tgrBig]; bigView.alpha = 0.2; UIScrollView *scrollerViewThree = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 300, 440 )];
scrollerViewThree.delegate = self;
scrollerViewThree.maximumZoomScale = 3.0;
scrollerViewThree.minimumZoomScale = 1;
[bigView addSubview: scrollerViewThree];
[scrollerViewThree addSubview:bigImageView]; }
-(void)beginSmall:(UIGestureRecognizer *)sender
{ NSLog(@"--doClickbeginSmall--"); [UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations]; bigView.alpha = 1; [bigImageView removeFromSuperview]; }
【代码笔记】iOS-两个滚动条,上下都能滑动的更多相关文章
- iOS开发笔记-两种单例模式的写法
iOS开发笔记-两种单例模式的写法 单例模式是开发中最常用的写法之一,iOS的单例模式有两种官方写法,如下: 不使用GCD #import "ServiceManager.h" ...
- Masonry -- 使用纯代码进行iOS应用的autolayout自适应布局
简介 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstraints. 项目主页: Masonry 最新示例: 点击下载 项目简议: 如果再看到关于纯代 ...
- 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程
一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...
- 【hadoop代码笔记】hadoop作业提交之汇总
一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- <Python Text Processing with NLTK 2.0 Cookbook>代码笔记
如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...
- Masonry — 使用纯代码进行iOS应用的autolayout自适应布局
本文转载至 http://www.ios122.com/2015/09/masonry/ 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstrain ...
- iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建
1. Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated. ...
- iOS 两种不同的图片无限轮播
代码地址如下:http://www.demodashi.com/demo/11608.html 前记 其实想写这个关于无限轮播的记录已经很久很久了,只是没什么时间,这只是一个借口,正如:时间就像海绵, ...
随机推荐
- 提取KIndle中每本书的笔记并单独保存
整体思路 目标:将Kindle中的每本书的笔记标注单独提取出保存为一个Markdown文件 其中检测KIndle是否已经正常插入的判断方法: 思路1:读取媒介挂载记录 思路2:直接判断挂载地址是否存在 ...
- C#基础04
介绍:泛型介绍,索引,Foreach遍历的解释,yield方法,path文件操作,Directory类基本操作<目录> 一:泛型 百度资料:泛型是 2.0 版 C# 语言和公共语言运行 ...
- 当前标识(IIS APPPOOL\dfcreport)没有对“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files”的写访问权限。
Asp.NET网站部署到IIS上面,浏览出现如下图所示错误. 原因原因最 原因: 1.IIS对该文件夹没有写的权限. 2.IIS和asp.net安装顺序错误,应该先IIS,然后asp.net. 3.没 ...
- 基于ListBox的相关操作
Winform中两个listbox的操作是平时比较常用的操作. 本次将以一个Winform实例来分享一下两个listbox的操作,包括:listbox添加项,项的上移下移等操作. 假设有两个listb ...
- 了解WP的传感器
之前看到老大的一个QQ签名,说想写一个WP的程序,可是后来,后来就没有后来了.我去年打算学一下WP程序开发的,一年了也无任何进展,我可不想后来,后来就没有后来.于是抽时间来接触一下.虽然都是用CShs ...
- R语言介绍
R语言简介 R语言是一种为统计计算和图形显示而设计的语言环境,是贝尔实验室(Bell Laboratories)的Rick Becker.John Chambers和Allan Wilks开发的S语言 ...
- C# WebClient 使用http免费代理。
static void Main(string[] args) { WebClient client = new WebClient(); client.Encoding = Encoding.Get ...
- Tomcat8访问管理页面localhost出现:403 Access Denied
问题: Access Denied You are not authorized to view this page. If you have already configured the Manag ...
- 【Java每日一题】20161025
20161024问题解析请点击今日问题下方的"[Java每日一题]20161025"查看 package Oct2016; import static java.lang.Math ...
- java中的几种取整函数
舍掉小数取整:Math.floor(2)=2 舍掉小数取整:Math.floor(2.1)=2 舍掉小数取整:Math.floor(2.5)=2 舍掉小数取整:Math.floor(2.9)=2 负数 ...