[Code Note] Two scroll bars can be slide up and down, and the scroll bar slides

Source: Internet
Author: User

[Code Note] Two scroll bars can be slide up and down, and the scroll bar slides

I ,.

 

 

2. Engineering Drawing.

3. Code.

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 *) bundle :( NSBundle *) handle {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 {// when you zoom in, bigView = [[UIView alloc] initWithFrame: CGRectMake (10, 10,300,440)]; [self. view addSubview: bigView]; // background image backView = [[UIView alloc] initWithFrame: CGRectMake (0, 0,320,460)]; [self. view addSubview: backView]; // background UIImageView * imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "backImage.png"]; imageView. frame = CGRectMake (0, 0,320,460); [backView addSubview: imageView]; // define 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 = [[UIScrollView alloc] initWithFrame: CGRectMake (0,152,320,308)]; details. 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]; // large background image of scrollerFirst (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] ;}// gallery on the scrollerFirst shelf 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; optional * tapGesture = [[financialloc] initWithTarget: self action: @ selector (doClickTapGesture :)]; [imageViewBook preview: tapGesture]; [scrollerViewFirst addSubview: imageViewBook];} // Title of 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];} // line in each 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"); // The result of a page being flipped from the right [UIView beginAnimations: nil context: nil]; [UIView setAnimationDuration: 0.7]; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView: self. view cache: YES]; [self. view history: 1 withSubviewAtIndex: 0]; [UIView history]; bigImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: [NSString stringWithFormat: @ "languld.png", tapGesture. view. tag + 1]; bigImageView. frame = CGRectMake (0, 0, 300,440); bigImageView. userInteractionEnabled = YES; required * tgrBig = [[financialloc] 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. vertex = 1; [bigView addSubview: scrollerViewThree]; [scrollerViewThree addSubview: bigImageView];}-(void) beginSmall :( vertex *) 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];}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.