• 同时控制多个UIScrollView对象


    效果:

    分别拖动下方和上方滚动视图

    用数组把所有的UIScrollView对象储存起来。

     1 #import "ViewController.h"
     2 
     3 @interface ViewController () <UIScrollViewDelegate>
     4 
     5 @end
     6 
     7 @implementation ViewController
     8 
     9 @synthesize scrollViews = _scrollViews;
    10 
    11 - (void)viewDidLoad
    12 {
    13     [super viewDidLoad];
    14     
    15     UIImageView *imgViewUp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
    16     UIScrollView *scrollViewUp = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, imgViewUp.frame.size.height)];
    17     scrollViewUp.contentSize = CGSizeMake(imgViewUp.frame.size.width, imgViewUp.frame.size.height);
    18     scrollViewUp.bounces = NO;
    19     scrollViewUp.clipsToBounds = YES;
    20     scrollViewUp.delegate = self;
    21     [scrollViewUp addSubview:imgViewUp];
    22     [self.view addSubview:scrollViewUp];
    23     /////////////////////////////////////////////////////////////////////////////////
    24     float height = imgViewUp.frame.size.height;
    25     UIImageView *imgViewCenter = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
    26     imgViewCenter.userInteractionEnabled = YES;
    27     UIScrollView *scrollViewCenter = [[UIScrollView alloc] initWithFrame:CGRectMake(0, height, self.view.frame.size.width, self.view.frame.size.height-height)];
    28     scrollViewCenter.contentSize = CGSizeMake(imgViewCenter.frame.size.width, imgViewCenter.frame.size.height);
    29     scrollViewCenter.bounces = NO;
    30     scrollViewCenter.clipsToBounds = YES;
    31     // scrollViewCenter的委托是本对象(ViewController)
    32     scrollViewCenter.delegate = self;
    33     [scrollViewCenter addSubview:imgViewCenter];
    34     [self.view addSubview:scrollViewCenter];
    35     
    36     self.scrollViews = [NSArray arrayWithObjects:scrollViewCenter, scrollViewUp, nil];
    37 }
    38 
    39 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    40 {
    41     // 枚举UIScrollView对象数组中每一个对象
    42     for (UIScrollView *view in self.scrollViews) {
    43         // 对非当前UIScrollView对象进行设置偏移量(contentOffset)
    44         if (scrollView != view) {
    45             [view setContentOffset:scrollView.contentOffset];
    46         }
    47     }
    48 }


    /**************************************************************************
                      原文来自博客园——Submarinex的博客: www.cnblogs.com/submarinex/               
      *************************************************************************/

  • 相关阅读:
    2017年3月10号课堂笔记
    2017年3月8号课堂笔记
    2017年3月6号课堂笔记
    2017年3月3号课堂笔记
    第7讲:设计PE型病毒2
    第6讲:设计PE型病毒1
    第5讲:HOOK 任务管理器 第2种方法注入
    第4讲:HOOK 任务管理器 无法结束进程
    第3讲:导入表的定位和读取操作
    第2讲:搜索PEB结构获取kernel32.dll的基址暴力搜索内存空间获得 Api 的线性地址
  • 原文地址:https://www.cnblogs.com/submarinex/p/2810555.html
Copyright © 2020-2023  润新知