设为首页 加入收藏

TOP

【代码笔记】iOS-两个滚动条,上下都能滑动(一)
2017-10-13 10:33:05 】 浏览:9127
Tags:代码 笔记 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;
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【Swift学习】Swift编程之旅---扩.. 下一篇UITableView点击每个Cell,Cell的..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目