zoukankan      html  css  js  c++  java
  • 同时控制多个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/               
      *************************************************************************/

  • 相关阅读:
    关于界面和UI
    Windows Form编程中的Command模式
    转载:从地理学透视中国现代化
    [3sNews, 关外飞雪]2005年3S业界盘点暨《3S新闻周刊》创刊题记
    Bridge? 一个GIS二次开发中常用的设计模式
    2005年GIS技术盘点
    [3sNews]建立GIS人自己的工会,抵制低薪无薪上岗
    2005国产空间信息系统软件测评结果揭晓
    从语义(semantic)GIS和知识表达谈起
    使用编译器来使用宏变量
  • 原文地址:https://www.cnblogs.com/submarinex/p/2810555.html
Copyright © 2011-2022 走看看