【代码笔记】两个滚动条,上下都能滑动

一,效果图。

二,工程图。

三,代码。

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];

}

时间: 2024-10-18 10:32:41

【代码笔记】两个滚动条,上下都能滑动的相关文章

汇编代码笔记 动态更新中

汇编考完了,悲剧的93分,,,,,以后的汇编就用的少了,凡是用到都来这里做点代码笔记: 一.错误总结: 1.程序最后END +起始标号,否则U的时候需要自己手动找起始位置而且有可能程序翻译指令错误 2.对内存单元进行操作的时候,注意类型的指定,比如inc [si]必然是错的因为没有类型,还有处理数据计数器si注意加一 3.凡是用到[si]这种形式的,都注意声明BYTEPTR,WORD PTR 4.同3的错误,如果声明了COUNTDB 3,那么mov cx,count就是不对的,因为类型不匹配 5

笔记-[js兼容]-滚动条的滚动距离的兼容性问题解决方法。

在我们操作JS实现些效果的时候,可能会涉及到滚动条滚动距离的问题; 在IE和非IE下是存在兼容性问题的 在IE下支持:document.body.scrollTop(scrollLeft);//在ie下获取滚动条距离的属性 在非IE下支持:document.documentElement.scrollTop(scrollLeft);//在非ie下获取滚动条距离的属性 代码兼容: var scrollTop;//定义一个变量名为scrollTop为滚动条的距离 滚动高度 :  var scroll

程序打印自身代码的两种方法

程序打印自身代码的两种方法 方法一:利用fopen,打开可执行程序对应的source code file /***************************************** code writer : EOF code file : print_my_self.c code date : 2014.08.01 e-mail: [email protected] code purpose : Aha, print out myself! *********************

多线程二(GCD)代码笔记

// // TWFXViewController.h // Demo_GCD // // Created by Lion User on 12-12-11. // Copyright (c) 2012年 Lion User. All rights reserved. // #import <UIKit/UIKit.h> @interface TWFXViewController : UIViewController @property (retain, nonatomic) IBOutlet

《linux 内核完全剖析》 vsprintf.c 代码笔记

Flex1 到 Flex3 使用的都是 Halo组件,这里将介绍Halo 组件中的List 和 DataGrid .其中 DataGrid 是显示多列数据中最常用的方式.但是在Spark中还有没对应DataGrid的组件. 先写个"食物"的模型 Dinner.as . package model { [Bindable] public class Dinner { public var name:String; public var food:String; public var du

iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建

1. Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert. //UIAlertView和UI

前端努力的哪怕从代码的体积哪怕是20K都在努力减少的同时

久以前在安卓2.0系统刚刚的时候就对HTML5比较关注!因为我也是那个时候刚刚入行做前端的.那个时候最大的乐趣就是看着w3plus上面各种css3的效果,觉得哇,好牛逼原来可以这样做,然后3年过去了...手上的APP做完的没有40个也有30个了!然后去年参加了HTML5峰会.听着一批前辈们说着他们在html5的道路中遇到的挫折,经验,以及流行的框架,制作HTML5的ide...也算是小有经验了!...然后知道的越多,现实就越残酷(大漠竟然说他不会JS,无语偶曾经的偶像竟然说他真的不会js还发誓!

Effective Java读书笔记(3对于所有对象都通用的方法)

3.1 覆盖equals时请遵守通用约定 什么时候应该覆盖Object.equals()方法呢? 如果类具有自己特有的"逻辑相等"概念(不同于对象等同的概念),而且超类还没有覆盖equals以实现期望的行为,这时我们就需要覆盖equals方法. Object.equals()方法具有自反性.对称性.传递性.一致性和与null比较返回false的特点. 实现高质量equals方法的诀窍: (1)使用==操作符检查"参数是否为这个对象的引用".如果是,则返回true,这

ORA-01810格式代码出现两次 的解决方案

今早做一个查询页面时,需要查询两个时间区间的跨度,使用TO_DATE函数,一开始写成了Sql代码 TO_DATE('2014-08-04 00:00:00','YYYY-MM-DD HH:mm:ss') 结果报ORA-01810 格式代码出现两次的错误.后来上网查询后,发现是格式化字符串有问题,其中不应该将某个格式重复两次,否则Oracle就不知道要从哪个占位区间去解析该字段了,正确的格式应该是这样的,用MI来代表分钟 正确Sql代码 :TO_CHAR('2014-08-04 00:00:00'

jquery两个滚动条样式

jquery两个滚动条样式 点击下载