首页 技术 正文
技术 2022年11月16日
0 收藏 514 点赞 4,670 浏览 5304 个字

一,效果图。

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

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

二,工程图。

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

三,代码。

RootViewController.h

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

#import <UIKit/UIKit.h>@interface RootViewController : UIViewController
<UIScrollViewDelegate>
{
UIView *backView;
UIScrollView *scrollerViewFirst;
UIScrollView *scrollerViewSecond;
UIImageView * imageViewBook;
UILabel *label;
UIImageView *bigImageView;
UIView *bigView;
}@end

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

RootViewController.m

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

#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-两个滚动条,上下都能滑动  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851