同时控制多个UIScrollView对象
<div class="postcontent"><div id="cnblogs_post_body">效果:分别拖动下方和上方滚动视图
http://pic002.cnblogs.com/images/2012/266130/2012120922411762.pnghttp://pic002.cnblogs.com/images/2012/266130/2012120922441651.png
用数组把所有的UIScrollView对象储存起来。
<div class="cnblogs_code"> 1 #import "ViewController.h" 2 3 @interface ViewController () <UIScrollViewDelegate> 4 5 @end 6 7 @implementation ViewController 8 9 @synthesize scrollViews = _scrollViews;10 11 - (void)viewDidLoad12 {13 ;14 15 UIImageView *imgViewUp = [ initWithImage:@"2.png"]];16 UIScrollView *scrollViewUp = [ 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 ;22 ;23 /////////////////////////////////////////////////////////////////////////////////24 float height = imgViewUp.frame.size.height;25 UIImageView *imgViewCenter = [ initWithImage:@"1.png"]];26 imgViewCenter.userInteractionEnabled = YES;27 UIScrollView *scrollViewCenter = [ 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 ;34 ;35 36 self.scrollViews = ;37 }38 39 - (void)scrollViewDidScroll:(UIScrollView *)scrollView40 {41 // 枚举UIScrollView对象数组中每一个对象42 for (UIScrollView *view in self.scrollViews) {43 // 对非当前UIScrollView对象进行设置偏移量(contentOffset)44 if (scrollView != view) {45 ;46 }47 }48 }
页:
[1]