ios如何同时控制多个UIScroll
操作方法
- 01
所谓万事开头难,ios学习也是这样,现在介绍一些ios教程的应用技巧给大家作参考,希望对大家对ios同时控制多个UIScroll知识有更多的了解。 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 } 好了,通过以上的讲解,是不是对ios培训中这个知识点掌握的更多了呢,希望今天的讲解能够帮助到你。