├── LazyScrollView ├── LazyScrollView.xcodeproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── xcuserdata │ │ └── xiabob.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── LazyScrollView.xcscheme │ └── project.pbxproj └── LazyScrollView │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── SingleView.h │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── SingleView.m │ ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard │ ├── Classes │ ├── LazyScrollView.h │ └── LazyScrollView.m │ ├── AppDelegate.m │ └── ViewController.m ├── LICENSE ├── README.md └── Classes ├── LazyScrollView.h └── LazyScrollView.m /LazyScrollView/LazyScrollView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/SingleView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SingleView.h 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern NSString * const kViewIdfSingle1; 12 | extern NSString * const kViewIdfSingle2; 13 | extern NSString * const kViewIdfSingle3; 14 | extern NSString * const kViewIdfSingle4; 15 | extern NSString * const kViewIdfSingle5; 16 | 17 | @interface SingleView : UIView 18 | 19 | @property (nonatomic, copy) NSString *data; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView.xcodeproj/xcuserdata/xiabob.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LazyScrollView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 743FAFA31E0BBA54008097E9 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LazyScrollView 2 | iOS 高性能异构滚动视图构建方案 —— LazyScrollView 3 | 4 | ##思路来源 5 | * [苹果核 - iOS 高性能异构滚动视图构建方案 —— LazyScrollView](http://pingguohe.net/2016/01/31/lazyscroll.html) 6 | 7 | 已开源https://github.com/alibaba/LazyScrollView 8 | ##使用 9 | 10 | 使用方式和tableView类似,具体还是参照工程里面的例子。 11 | ###dataSource 12 |
13 | // ScrollView一共需要展示多少个item
14 | - (NSUInteger)numberOfItemInScrollView:(LazyScrollView *)scrollView;
15 | // 要求根据index直接返回RectModel
16 | - (LSVRectModel *)scrollView:(LazyScrollView *)scrollView rectModelAtIndex:(NSUInteger)index;
17 | // 返回下标所对应的view
18 | - (UIView *)scrollView:(LazyScrollView *)scrollView itemByLsvId:(NSString *)lsvId;
19 | 
20 | 其中LSVRectModel的定义如下: 21 |
22 | // view转换后的绝对值rect
23 | @property (nonatomic, assign) CGRect absRect;
24 | 
25 | // 业务下标,如果初始化时没有提供,LSVRectModel内部会自动生成
26 | @property (nonatomic, copy) NSString *lsvId;
27 | 
28 | 关键在于方法- (LSVRectModel *)scrollView:(LazyScrollView *)scrollView rectModelAtIndex:(NSUInteger)index,具体可以参见demo工程。 29 | 30 | ###delegate 31 |
32 | //处理点击事件
33 | - (void)scrollView:(LazyScrollView *)scrollView didClickItemAtIndex:(NSUInteger)index;
34 | 
35 | 36 | ###调用核心API 37 |
38 | - (void)reloadData;
39 | 
40 | 41 | 重新走一遍DataSource的这些方法,等同于TableView中的reloadData 42 |
43 | - (UIView *)dequeueReusableItemWithIdentifier:(NSString *)identifier
44 | 
45 | 46 | 根据identifier获取可以复用的View。和TableView的dequeueReusableCellWithIdentifier:(NSString *)identifier方法意义相同。通常是在LazyScrollViewDatasource第三个方法,返回View的时候使用。 47 | 48 |
49 | - (void)registerClass:(Class)viewClass forViewReuseIdentifier:(NSString *)identifier
50 | 
51 | 52 | 功能和TableView的registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier一样 53 | tableView 54 | 55 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/SingleView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SingleView.m 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import "SingleView.h" 10 | 11 | NSString * const kViewIdfSingle1 = @"kViewIdfSingle1"; 12 | NSString * const kViewIdfSingle2 = @"kViewIdfSingle2"; 13 | NSString * const kViewIdfSingle3 = @"kViewIdfSingle3"; 14 | NSString * const kViewIdfSingle4 = @"kViewIdfSingle4"; 15 | NSString * const kViewIdfSingle5 = @"kViewIdfSingle5"; 16 | 17 | @interface SingleView () 18 | @property (nonatomic, strong) UILabel *title; 19 | @end 20 | 21 | @implementation SingleView 22 | 23 | - (instancetype)initWithFrame:(CGRect)frame { 24 | if (self = [super initWithFrame:frame]) { 25 | [self setupUI]; 26 | } 27 | return self; 28 | } 29 | 30 | - (void)setupUI { 31 | 32 | self.backgroundColor = [self randomColor]; 33 | 34 | [self addSubview:self.title]; 35 | 36 | self.title.frame = CGRectMake(0, 0, 100, 50); 37 | } 38 | 39 | - (UIColor *)randomColor { 40 | CGFloat hue = ( arc4random() % 361 / 360.0 ); 41 | CGFloat saturation = ( arc4random() % 101 / 100.0 ); 42 | CGFloat brightness = ( arc4random() % 101 / 100.0 ); 43 | //hsb 44 | return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1]; 45 | } 46 | 47 | #pragma mark - setter 48 | 49 | - (void)setData:(NSString *)data { 50 | _data = data; 51 | self.title.text = data; 52 | } 53 | 54 | #pragma mark - getter 55 | 56 | - (UILabel *)title { 57 | if (!_title) { 58 | _title = [UILabel new]; 59 | _title.font = [UIFont systemFontOfSize:13.f]; 60 | _title.textColor = [UIColor whiteColor]; 61 | } 62 | return _title; 63 | } 64 | 65 | @end 66 | 67 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Classes/LazyScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LazyScrollView.h 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import 10 | @class LSVRectModel; 11 | @class LazyScrollView; 12 | 13 | typedef NS_ENUM(NSUInteger, LazyScrollViewDirection) { 14 | LazyScrollViewDirectionHorizontal, 15 | LazyScrollViewDirectionVertical, 16 | }; 17 | 18 | 19 | #pragma mark - LazyScrollViewDataSource 20 | 21 | @protocol LazyScrollViewDataSource 22 | 23 | @required 24 | // ScrollView一共展示多少个item 25 | - (NSUInteger)numberOfItemInScrollView:(LazyScrollView *)scrollView; 26 | // 要求根据index直接返回RectModel 27 | - (LSVRectModel *)scrollView:(LazyScrollView *)scrollView rectModelAtIndex:(NSUInteger)index; 28 | // 返回下标所对应的view 29 | - (UIView *)scrollView:(LazyScrollView *)scrollView itemByLsvId:(NSString *)lsvId; 30 | 31 | @end 32 | 33 | #pragma mark - LazyScrollViewDelegate 34 | 35 | @protocol LazyScrollViewDelegate 36 | 37 | @optional 38 | - (void)scrollView:(LazyScrollView *)scrollView didClickItemAtIndex:(NSUInteger)index; 39 | 40 | @end 41 | 42 | 43 | #pragma mark - LazyScrollView 44 | 45 | @interface LazyScrollView : UIScrollView 46 | 47 | @property (nonatomic, weak) id dataSource; 48 | @property (nonatomic, weak) id delegate; 49 | 50 | /** 51 | * 滚动方向 52 | * 暂时只支持 `LazyScrollViewDirectionVertical` 53 | */ 54 | //@property (nonatomic, assign) LazyScrollViewDirection direction; 55 | 56 | - (void)reloadData; 57 | - (UIView *)dequeueReusableItemWithIdentifier:(NSString *)identifier; 58 | - (void)registerClass:(Class)viewClass forViewReuseIdentifier:(NSString *)identifier; 59 | 60 | @end 61 | 62 | 63 | #pragma mark - LSVRectModel 64 | 65 | @interface LSVRectModel : NSObject 66 | // view转换后的绝对值rect 67 | @property (nonatomic, assign) CGRect absRect; 68 | 69 | // 业务下标,如果初始化时没有提供,LSVRectModel内部会自动生成 70 | @property (nonatomic, copy) NSString *lsvId; 71 | 72 | + (instancetype)modelWithRect:(CGRect)rect; 73 | + (instancetype)modelWithRect:(CGRect)rect lsvId:(NSString *)lsvId; 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/Classes/LazyScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LazyScrollView.h 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import 10 | @class LSVRectModel; 11 | @class LazyScrollView; 12 | 13 | typedef NS_ENUM(NSUInteger, LazyScrollViewDirection) { 14 | LazyScrollViewDirectionHorizontal, 15 | LazyScrollViewDirectionVertical, 16 | }; 17 | 18 | 19 | #pragma mark - LazyScrollViewDataSource 20 | 21 | @protocol LazyScrollViewDataSource 22 | 23 | @required 24 | /// ScrollView一共展示多少个item 25 | - (NSUInteger)numberOfItemInScrollView:(LazyScrollView *)scrollView; 26 | /// 要求根据index直接返回RectModel 27 | - (LSVRectModel *)scrollView:(LazyScrollView *)scrollView rectModelAtIndex:(NSUInteger)index; 28 | /// 返回下标所对应的view 29 | - (UIView *)scrollView:(LazyScrollView *)scrollView itemByLsvId:(NSString *)lsvId; 30 | 31 | @end 32 | 33 | #pragma mark - LazyScrollViewDelegate 34 | 35 | @protocol LazyScrollViewDelegate 36 | 37 | @optional 38 | ///点击了对应小标的cell 39 | - (void)scrollView:(LazyScrollView *)scrollView didClickItemAtIndex:(NSUInteger)index withLsvId:(NSString *)lsvId; 40 | 41 | @end 42 | 43 | 44 | #pragma mark - LazyScrollView 45 | 46 | @interface LazyScrollView : UIScrollView 47 | 48 | @property (nonatomic, weak) id dataSource; 49 | @property (nonatomic, weak) id delegate; 50 | 51 | /** 52 | * 滚动方向 53 | * 暂时只支持 `LazyScrollViewDirectionVertical` 54 | */ 55 | //@property (nonatomic, assign) LazyScrollViewDirection direction; 56 | 57 | - (void)reloadData; 58 | - (UIView *)dequeueReusableItemWithIdentifier:(NSString *)identifier; 59 | - (void)registerClass:(Class)viewClass forViewReuseIdentifier:(NSString *)identifier; 60 | 61 | @end 62 | 63 | 64 | #pragma mark - LSVRectModel 65 | 66 | @interface LSVRectModel : NSObject 67 | /// view转换后的绝对值rect 68 | @property (nonatomic, assign) CGRect absRect; 69 | 70 | /// 业务下标,如果初始化时没有提供,LSVRectModel内部会自动生成 71 | @property (nonatomic, copy) NSString *lsvId; 72 | 73 | + (instancetype)modelWithRect:(CGRect)rect; 74 | + (instancetype)modelWithRect:(CGRect)rect lsvId:(NSString *)lsvId; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView.xcodeproj/xcuserdata/xiabob.xcuserdatad/xcschemes/LazyScrollView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LazyScrollView.h" 11 | #import "SingleView.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (strong, nonatomic) LazyScrollView *lazyScrollView; 16 | @property (copy, nonatomic) NSArray *rectDatas; 17 | @property (copy, nonatomic) NSDictionary *viewsData; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)loadView { 24 | [super loadView]; 25 | 26 | [self loadDatas]; 27 | [self configViews]; 28 | } 29 | 30 | - (void)viewDidLoad { 31 | [super viewDidLoad]; 32 | // Do any additional setup after loading the view, typically from a nib. 33 | } 34 | 35 | - (void)loadDatas { 36 | 37 | NSMutableArray *array = @[].mutableCopy; 38 | NSMutableDictionary *dictionary = @{}.mutableCopy; 39 | 40 | NSMutableArray *rectArray = [[NSMutableArray alloc] init]; 41 | //Create a single column layout with 5 elements; 42 | for (int i = 0; i < 500 ; i++) { 43 | [rectArray addObject:[NSValue valueWithCGRect:CGRectMake(10, i *80 + 2 , self.view.bounds.size.width-20, 80-2)]]; 44 | } 45 | //Create a double column layout with 10 elements; 46 | for (int i = 0; i < 1000 ; i++) { 47 | [rectArray addObject:[NSValue valueWithCGRect:CGRectMake((i%2)*self.view.bounds.size.width/2 + 3, 41000 + i/2 *80 + 2 , self.view.bounds.size.width/2 -3, 80 - 2)]]; 48 | } 49 | //Create a trible column layout with 15 elements; 50 | for (int i = 0; i < 1500 ; i++) { 51 | NSUInteger row = 5; 52 | [rectArray addObject:[NSValue valueWithCGRect:CGRectMake((i%row)*self.view.bounds.size.width/row + 1, 82000 + i/row *80 + 2 , self.view.bounds.size.width/row -4, 80 - 2)]]; 53 | } 54 | 55 | for (NSInteger index = 0; index < rectArray.count; ++ index) { 56 | NSString *lsvId = [NSString stringWithFormat:@"%@/%@", @(index / 10), @(index % 10)]; 57 | LSVRectModel *model = [LSVRectModel modelWithRect:[(NSValue *)(rectArray[index]) CGRectValue] lsvId:lsvId]; 58 | [array addObject:model]; 59 | [dictionary setObject:lsvId forKey:lsvId]; 60 | } 61 | 62 | 63 | // for (NSInteger index = 0; index < 5000; ++ index) { 64 | // NSString *lsvId = [NSString stringWithFormat:@"%@/%@", @(index / 10), @(index % 10)]; 65 | // CGFloat width = ([UIScreen mainScreen].bounds.size.width - 30) / 2; 66 | // LSVRectModel *model = [LSVRectModel modelWithRect:CGRectMake(10 + (index % 2) * (width+10), (index / 2) * (width+10), width, width) lsvId:lsvId]; 67 | // [array addObject:model]; 68 | // [dictionary setObject:lsvId forKey:lsvId]; 69 | // } 70 | self.rectDatas = array; 71 | self.viewsData = dictionary; 72 | 73 | } 74 | 75 | - (void)configViews { 76 | 77 | self.view.backgroundColor = [UIColor whiteColor]; 78 | 79 | [self.view addSubview:self.lazyScrollView]; 80 | self.lazyScrollView.frame = self.view.bounds; 81 | 82 | } 83 | 84 | - (void)didReceiveMemoryWarning { 85 | [super didReceiveMemoryWarning]; 86 | // Dispose of any resources that can be recreated. 87 | } 88 | 89 | #pragma mark - LazyScrollViewDataSource 90 | 91 | - (NSUInteger)numberOfItemInScrollView:(LazyScrollView *)scrollView { 92 | return self.rectDatas.count; 93 | } 94 | 95 | - (LSVRectModel *)scrollView:(LazyScrollView *)scrollView rectModelAtIndex:(NSUInteger)index { 96 | 97 | return self.rectDatas[index]; 98 | } 99 | 100 | - (UIView *)scrollView:(LazyScrollView *)scrollView itemByLsvId:(NSString *)lsvId { 101 | SingleView *view; 102 | NSInteger index = [[[lsvId componentsSeparatedByString:@"/"] valueForKeyPath:@"@sum.integerValue"] integerValue]; 103 | if (index % 3 == 1) { 104 | view = (SingleView *)[self.lazyScrollView dequeueReusableItemWithIdentifier:kViewIdfSingle1]; 105 | view.data = [NSString stringWithFormat:@"Single1 - %@", self.viewsData[lsvId]]; 106 | } else if (index % 5 == 2 || index % 5 == 3) { 107 | view = (SingleView *)[self.lazyScrollView dequeueReusableItemWithIdentifier:kViewIdfSingle2]; 108 | view.data = [NSString stringWithFormat:@"Single2 - %@", self.viewsData[lsvId]]; 109 | } else if (index % 7 == 3 || index % 7 == 2) { 110 | view = (SingleView *)[self.lazyScrollView dequeueReusableItemWithIdentifier:kViewIdfSingle3]; 111 | view.data = [NSString stringWithFormat:@"Single3 - %@", self.viewsData[lsvId]]; 112 | } else if (index % 7 == 4 || index % 7 == 5) { 113 | view = (SingleView *)[self.lazyScrollView dequeueReusableItemWithIdentifier:kViewIdfSingle4]; 114 | view.data = [NSString stringWithFormat:@"Single4 - %@", self.viewsData[lsvId]]; 115 | } else { 116 | view = (SingleView *)[self.lazyScrollView dequeueReusableItemWithIdentifier:kViewIdfSingle5]; 117 | view.data = [NSString stringWithFormat:@"Single5 - %@", self.viewsData[lsvId]]; 118 | } 119 | 120 | return view; 121 | } 122 | 123 | #pragma mark - LazyScrollViewDelegate 124 | 125 | - (void)scrollView:(LazyScrollView *)scrollView didClickItemAtIndex:(NSUInteger)index withLsvId:(NSString *)lsvId { 126 | SingleView *view = (SingleView *)[self scrollView:scrollView itemByLsvId:lsvId]; 127 | NSLog(@"didClickItemAtIndex:%@ lsvid:%@ view data:%@", @(index), lsvId, view.data); 128 | [scrollView reloadData]; 129 | } 130 | 131 | 132 | #pragma mark - getter 133 | 134 | - (LazyScrollView *)lazyScrollView { 135 | if (!_lazyScrollView) { 136 | _lazyScrollView = [LazyScrollView new]; 137 | _lazyScrollView.dataSource = self; 138 | _lazyScrollView.delegate = self; 139 | [_lazyScrollView registerClass:[SingleView class] forViewReuseIdentifier:kViewIdfSingle1]; 140 | [_lazyScrollView registerClass:[SingleView class] forViewReuseIdentifier:kViewIdfSingle2]; 141 | [_lazyScrollView registerClass:[SingleView class] forViewReuseIdentifier:kViewIdfSingle3]; 142 | [_lazyScrollView registerClass:[SingleView class] forViewReuseIdentifier:kViewIdfSingle4]; 143 | [_lazyScrollView registerClass:[SingleView class] forViewReuseIdentifier:kViewIdfSingle5]; 144 | } 145 | return _lazyScrollView; 146 | } 147 | 148 | - (NSArray *)rectDatas { 149 | if (!_rectDatas) { 150 | _rectDatas = [NSArray array]; 151 | } 152 | return _rectDatas; 153 | } 154 | 155 | - (NSDictionary *)viewsData { 156 | if (!_viewsData) { 157 | _viewsData = [NSDictionary dictionary]; 158 | } 159 | return _viewsData; 160 | } 161 | 162 | @end 163 | -------------------------------------------------------------------------------- /Classes/LazyScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LazyScrollView.m 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import "LazyScrollView.h" 10 | #import 11 | 12 | CGFloat const kBufferSize = 20; 13 | 14 | 15 | #pragma mark - UIView (LSV) 16 | 17 | static char kAssociatedObjectKeylsvId; 18 | static char kAssociatedObjectKeyReuseIdentifier; 19 | 20 | @interface UIView (LSV) 21 | 22 | // 索引过的标识,在LazyScrollView范围内唯一 23 | @property (nonatomic, copy) NSString *lsvId; 24 | // 重用的ID 25 | @property (nonatomic, copy) NSString *reuseIdentifier; 26 | 27 | @end 28 | 29 | @implementation UIView (LSV) 30 | - (NSString *)lsvId { 31 | return objc_getAssociatedObject(self, &kAssociatedObjectKeylsvId); 32 | } 33 | 34 | - (void)setLsvId:(NSString *)lsvId { 35 | objc_setAssociatedObject(self, &kAssociatedObjectKeylsvId, lsvId, OBJC_ASSOCIATION_COPY_NONATOMIC); 36 | } 37 | 38 | - (NSString *)reuseIdentifier { 39 | return objc_getAssociatedObject(self, &kAssociatedObjectKeyReuseIdentifier); 40 | } 41 | 42 | - (void)setReuseIdentifier:(NSString *)reuseIdentifier { 43 | objc_setAssociatedObject(self, &kAssociatedObjectKeyReuseIdentifier, reuseIdentifier, OBJC_ASSOCIATION_COPY_NONATOMIC); 44 | } 45 | 46 | @end 47 | 48 | 49 | #pragma mark - LazyScrollView 50 | 51 | @interface LazyScrollView () 52 | 53 | @property (nonatomic, strong) NSMutableDictionary *reuseViewPool; 54 | @property (nonatomic, strong) NSMutableSet<__kindof UIView *> *visibleViews; 55 | 56 | @property (nonatomic, strong) NSMutableArray *allRectModels; 57 | @property (nonatomic, strong) NSMutableArray *allAscendingRectModels; //按照view顶部的y升序排列allRectModels 58 | @property (nonatomic, strong) NSMutableArray *allDescendingRectModels; //按照view底部的y降序排列allRectModels 59 | 60 | @property (nonatomic, assign) NSUInteger numberOfItems; 61 | 62 | @property (nonatomic, strong) NSMutableDictionary *registerClass; 63 | 64 | @property (nonatomic, strong) UITapGestureRecognizer *tapGesture; 65 | 66 | @end 67 | 68 | @implementation LazyScrollView 69 | 70 | @dynamic delegate; //消除警告 71 | 72 | - (instancetype)init { 73 | if (self = [super init]) { 74 | [self addGestureRecognizer:self.tapGesture]; 75 | } 76 | 77 | return self; 78 | } 79 | 80 | - (void)layoutSubviews { 81 | [super layoutSubviews]; 82 | // TOOD: 此处算法待优化 83 | NSMutableArray *newVisibleViews = [self getVisiableViewModels].mutableCopy; 84 | NSMutableArray *newVisibleLsvIds = [newVisibleViews valueForKey:@"lsvId"]; 85 | NSMutableArray *removeViews = [NSMutableArray array]; 86 | for (UIView *view in self.visibleViews) { 87 | if (![newVisibleLsvIds containsObject:view.lsvId]) { 88 | [removeViews addObject:view]; 89 | } 90 | } 91 | 92 | for (UIView *view in removeViews) { 93 | [self.visibleViews removeObject:view]; 94 | [self enqueueReusableView:view]; 95 | view.hidden = YES; 96 | } 97 | 98 | NSMutableArray *alreadyVisibles = [self.visibleViews valueForKey:@"lsvId"]; 99 | 100 | for (LSVRectModel *model in newVisibleViews) { 101 | if ([alreadyVisibles containsObject:model.lsvId]) { 102 | continue; 103 | } 104 | UIView *view = [self.dataSource scrollView:self itemByLsvId:model.lsvId]; 105 | view.frame = model.absRect; 106 | view.lsvId = model.lsvId; 107 | view.hidden = NO; 108 | 109 | [self.visibleViews addObject:view]; 110 | [self addSubview:view]; 111 | } 112 | 113 | } 114 | 115 | - (void)reloadData { 116 | [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 117 | [self.visibleViews removeAllObjects]; 118 | 119 | [self updateAllDatas]; 120 | } 121 | 122 | - (void)enqueueReusableView:(UIView *)view { 123 | if (!view.reuseIdentifier) { 124 | return; 125 | } 126 | 127 | NSString *identifier = view.reuseIdentifier; 128 | NSMutableSet *reuseSet = self.reuseViewPool[identifier]; 129 | if (!reuseSet) { 130 | reuseSet = [NSMutableSet set]; 131 | [self.reuseViewPool setValue:reuseSet forKey:identifier]; 132 | } 133 | [reuseSet addObject:view]; 134 | } 135 | 136 | - (UIView *)dequeueReusableItemWithIdentifier:(NSString *)identifier { 137 | if (!identifier) { 138 | return nil; 139 | } 140 | NSMutableSet *reuseSet = self.reuseViewPool[identifier]; 141 | UIView *view = [reuseSet anyObject]; 142 | if (view) { 143 | [reuseSet removeObject:view]; 144 | return view; 145 | } 146 | else { 147 | Class viewClass = [self.registerClass objectForKey:identifier]; 148 | view = [viewClass new]; 149 | view.reuseIdentifier = identifier; 150 | return view; 151 | } 152 | } 153 | 154 | - (void)registerClass:(Class)viewClass forViewReuseIdentifier:(NSString *)identifier { 155 | [self.registerClass setValue:viewClass forKey:identifier]; 156 | } 157 | 158 | #pragma mark - Utils 159 | 160 | - (CGFloat)minEdgeOffset { 161 | CGFloat min = CGRectGetMinY(self.bounds); 162 | return MAX(min - kBufferSize, 0); 163 | } 164 | 165 | - (CGFloat)maxEdgeOffset { 166 | CGFloat max = CGRectGetMaxY(self.bounds); 167 | return MIN(max + kBufferSize, self.contentSize.height); 168 | } 169 | 170 | - (LSVRectModel *)findFirstAscendModelWithMinEdge:(CGFloat)minEdge { 171 | // 二分法 172 | NSInteger minIndex = 0; 173 | NSInteger maxIndex = self.allAscendingRectModels.count - 1; 174 | NSInteger midIndex = (minIndex + maxIndex) / 2; 175 | LSVRectModel *model = self.allAscendingRectModels[midIndex]; 176 | 177 | while (minIndex < maxIndex - 1) { 178 | if (CGRectGetMinY(model.absRect) > minEdge) { 179 | maxIndex = midIndex; 180 | } 181 | else { 182 | minIndex = midIndex; 183 | } 184 | midIndex = (minIndex + maxIndex) / 2; 185 | model = self.allAscendingRectModels[midIndex]; 186 | } 187 | 188 | midIndex = MAX(midIndex - 1, 0); 189 | 190 | return self.allAscendingRectModels[midIndex]; 191 | } 192 | 193 | - (LSVRectModel *)findFirstDescendModelWithMaxEdge:(CGFloat)maxEdge { 194 | // 二分法 195 | NSInteger minIndex = 0; 196 | NSInteger maxIndex = self.allDescendingRectModels.count - 1; 197 | NSInteger midIndex = (minIndex + maxIndex) / 2; 198 | LSVRectModel *model = self.allDescendingRectModels[midIndex]; 199 | 200 | while (minIndex < maxIndex - 1) { 201 | if (CGRectGetMaxY(model.absRect) < maxEdge) { 202 | maxIndex = midIndex; 203 | } 204 | else { 205 | minIndex = midIndex; 206 | } 207 | midIndex = (minIndex + maxIndex) / 2; 208 | model = self.allDescendingRectModels[midIndex]; 209 | } 210 | 211 | midIndex = MAX(midIndex - 1, 0); 212 | 213 | return self.allDescendingRectModels[midIndex]; 214 | } 215 | 216 | - (NSArray *)getVisiableViewModels { 217 | // Descend e-----------------|s 218 | // --------------------------- Y值 219 | // s|------------e Ascend 220 | // 实际就是两个firstIndex的交叉部分 221 | LSVRectModel *firstAscendModel = [self findFirstAscendModelWithMinEdge:[self minEdgeOffset]]; 222 | LSVRectModel *firstDescendModel = [self findFirstDescendModelWithMaxEdge:[self maxEdgeOffset]]; 223 | 224 | NSInteger firstIndex = [self.allAscendingRectModels indexOfObject:firstAscendModel]; 225 | firstIndex = MAX(firstIndex-1, 0); 226 | NSInteger lastIndex = [self.allAscendingRectModels indexOfObject:firstDescendModel]; 227 | lastIndex = MIN(lastIndex+1, self.allAscendingRectModels.count-1); 228 | 229 | return [self.allAscendingRectModels subarrayWithRange:NSMakeRange(firstIndex, lastIndex-firstIndex+1)]; 230 | } 231 | 232 | - (void)updateAllDatas { 233 | [self.allRectModels removeAllObjects]; 234 | self.allAscendingRectModels = nil; 235 | self.allDescendingRectModels = nil; 236 | 237 | _numberOfItems = [self.dataSource numberOfItemInScrollView:self]; 238 | 239 | for (NSInteger index = 0; index < _numberOfItems; ++ index) { 240 | LSVRectModel *model = [self.dataSource scrollView:self rectModelAtIndex:index]; 241 | [self.allRectModels addObject:model]; 242 | } 243 | 244 | LSVRectModel *model = self.allAscendingRectModels.lastObject; 245 | self.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), CGRectGetMaxY(model.absRect)); 246 | } 247 | 248 | - (void)handleTapAction:(UIGestureRecognizer *)gestureRecognizer { 249 | NSArray *visibleViews = [self getVisiableViewModels]; 250 | CGPoint tapPoint = [gestureRecognizer locationInView:self]; 251 | for (LSVRectModel *model in visibleViews) { 252 | if (CGRectContainsPoint(model.absRect, tapPoint)) { 253 | if ([self.delegate respondsToSelector:@selector(scrollView:didClickItemAtIndex:)]) { 254 | NSInteger index = [self.allRectModels indexOfObject:model]; 255 | [self.delegate scrollView:self didClickItemAtIndex:index]; 256 | } 257 | 258 | break; 259 | } 260 | } 261 | } 262 | 263 | 264 | #pragma mark - Setter 265 | 266 | - (void)setDataSource:(id)dataSource { 267 | if (dataSource != _dataSource) { 268 | _dataSource = dataSource; 269 | } 270 | if (_dataSource) { 271 | [self reloadData]; 272 | } 273 | } 274 | 275 | #pragma mark - Getter 276 | - (NSMutableDictionary *)reuseViewPool { 277 | if (!_reuseViewPool) { 278 | _reuseViewPool = [NSMutableDictionary new]; 279 | } 280 | return _reuseViewPool; 281 | } 282 | 283 | - (NSMutableArray *)allRectModels { 284 | if (!_allRectModels) { 285 | _allRectModels = [NSMutableArray new]; 286 | } 287 | return _allRectModels; 288 | } 289 | 290 | - (NSMutableArray *)allAscendingRectModels { 291 | if (!_allAscendingRectModels) { 292 | //升序 293 | _allAscendingRectModels = [[self.allRectModels 294 | sortedArrayUsingComparator:^NSComparisonResult(LSVRectModel *obj1, LSVRectModel *obj2) { 295 | return CGRectGetMinY(obj1.absRect) < CGRectGetMinY(obj2.absRect) ? NSOrderedAscending : NSOrderedDescending;} 296 | ] mutableCopy]; 297 | } 298 | 299 | return _allAscendingRectModels; 300 | } 301 | 302 | - (NSMutableArray *)allDescendingRectModels { 303 | if (!_allDescendingRectModels) { 304 | //需要降序,而sortedArrayUsingComparator的结果是ascending order,所以block里面的结果是相反的。 305 | _allDescendingRectModels = [[self.allRectModels 306 | sortedArrayUsingComparator:^NSComparisonResult(LSVRectModel *obj1, LSVRectModel *obj2) { 307 | return CGRectGetMaxY(obj1.absRect) < CGRectGetMaxY(obj2.absRect) ? NSOrderedDescending : NSOrderedAscending;} 308 | ] mutableCopy]; 309 | } 310 | 311 | return _allDescendingRectModels; 312 | } 313 | 314 | - (NSMutableDictionary *)registerClass { 315 | if (!_registerClass) { 316 | _registerClass = [NSMutableDictionary new]; 317 | } 318 | return _registerClass; 319 | } 320 | 321 | - (NSMutableSet *)visibleViews { 322 | if (!_visibleViews) { 323 | _visibleViews = [NSMutableSet set]; 324 | } 325 | return _visibleViews; 326 | } 327 | 328 | - (UITapGestureRecognizer *)tapGesture { 329 | if (!_tapGesture) { 330 | _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self 331 | action:@selector(handleTapAction:)]; 332 | } 333 | 334 | return _tapGesture; 335 | } 336 | 337 | @end 338 | 339 | 340 | 341 | @implementation LSVRectModel 342 | 343 | + (instancetype)modelWithRect:(CGRect)rect lsvId:(NSString *)lsvId { 344 | LSVRectModel *model = [[LSVRectModel alloc] init]; 345 | model.absRect = rect; 346 | 347 | if (lsvId.length == 0) { 348 | lsvId = NSStringFromCGRect(rect); 349 | } 350 | model.lsvId = lsvId; 351 | 352 | return model; 353 | } 354 | 355 | + (instancetype)modelWithRect:(CGRect)rect { 356 | return [self modelWithRect:rect lsvId:nil]; 357 | } 358 | 359 | @end 360 | 361 | 362 | 363 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView/Classes/LazyScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LazyScrollView.m 3 | // LazyScrollView 4 | // 5 | // Created by xiabob on 16/12/22. 6 | // Copyright © 2016年 xiabob. All rights reserved. 7 | // 8 | 9 | #import "LazyScrollView.h" 10 | #import 11 | 12 | CGFloat const kBufferSize = 20; 13 | 14 | 15 | #pragma mark - UIView (LSV) 16 | 17 | static char kAssociatedObjectKeylsvId; 18 | static char kAssociatedObjectKeyReuseIdentifier; 19 | 20 | @interface UIView (LSV) 21 | 22 | // 索引过的标识,在LazyScrollView范围内唯一 23 | @property (nonatomic, copy) NSString *lsvId; 24 | // 重用的ID 25 | @property (nonatomic, copy) NSString *reuseIdentifier; 26 | 27 | @end 28 | 29 | @implementation UIView (LSV) 30 | - (NSString *)lsvId { 31 | return objc_getAssociatedObject(self, &kAssociatedObjectKeylsvId); 32 | } 33 | 34 | - (void)setLsvId:(NSString *)lsvId { 35 | objc_setAssociatedObject(self, &kAssociatedObjectKeylsvId, lsvId, OBJC_ASSOCIATION_COPY_NONATOMIC); 36 | } 37 | 38 | - (NSString *)reuseIdentifier { 39 | return objc_getAssociatedObject(self, &kAssociatedObjectKeyReuseIdentifier); 40 | } 41 | 42 | - (void)setReuseIdentifier:(NSString *)reuseIdentifier { 43 | objc_setAssociatedObject(self, &kAssociatedObjectKeyReuseIdentifier, reuseIdentifier, OBJC_ASSOCIATION_COPY_NONATOMIC); 44 | } 45 | 46 | @end 47 | 48 | 49 | #pragma mark - LazyScrollView 50 | 51 | @interface LazyScrollView () 52 | 53 | @property (nonatomic, strong) NSMutableDictionary *reuseViewPool; 54 | @property (nonatomic, strong) NSMutableSet<__kindof UIView *> *visibleViews; 55 | 56 | @property (nonatomic, strong) NSMutableArray *allRectModels; 57 | @property (nonatomic, strong) NSMutableArray *allAscendingRectModels; //按照view顶部的y升序排列allRectModels 58 | @property (nonatomic, strong) NSMutableArray *allDescendingRectModels; //按照view底部的y降序排列allRectModels 59 | 60 | @property (nonatomic, assign) NSUInteger numberOfItems; 61 | 62 | @property (nonatomic, strong) NSMutableDictionary *registerClass; 63 | 64 | @property (nonatomic, strong) UITapGestureRecognizer *tapGesture; 65 | 66 | @end 67 | 68 | @implementation LazyScrollView 69 | 70 | @dynamic delegate; //消除警告 71 | 72 | - (instancetype)init { 73 | if (self = [super init]) { 74 | [self addGestureRecognizer:self.tapGesture]; 75 | } 76 | 77 | return self; 78 | } 79 | 80 | - (void)layoutSubviews { 81 | [super layoutSubviews]; 82 | 83 | NSMutableArray *newVisibleViews = [self getVisiableViewModels].mutableCopy; 84 | NSMutableArray *newVisibleLsvIds = [newVisibleViews valueForKey:@"lsvId"]; 85 | NSMutableArray *removeViews = [NSMutableArray array]; 86 | for (UIView *view in self.visibleViews) { 87 | if (![newVisibleLsvIds containsObject:view.lsvId]) { 88 | [removeViews addObject:view]; 89 | } 90 | } 91 | 92 | for (UIView *view in removeViews) { 93 | [self.visibleViews removeObject:view]; 94 | [self enqueueReusableView:view]; 95 | view.hidden = YES; 96 | } 97 | 98 | NSMutableArray *alreadyVisibles = [self.visibleViews valueForKey:@"lsvId"]; 99 | 100 | for (LSVRectModel *model in newVisibleViews) { 101 | if ([alreadyVisibles containsObject:model.lsvId]) { 102 | continue; 103 | } 104 | UIView *view = [self.dataSource scrollView:self itemByLsvId:model.lsvId]; 105 | view.frame = model.absRect; 106 | view.lsvId = model.lsvId; 107 | view.hidden = NO; 108 | 109 | [self.visibleViews addObject:view]; 110 | [self addSubview:view]; 111 | } 112 | 113 | } 114 | 115 | - (void)reloadData { 116 | [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 117 | [self.visibleViews removeAllObjects]; 118 | [self.reuseViewPool removeAllObjects]; 119 | 120 | [self updateModelDatas]; 121 | } 122 | 123 | - (void)enqueueReusableView:(UIView *)view { 124 | if (!view.reuseIdentifier) { 125 | return; 126 | } 127 | 128 | NSString *identifier = view.reuseIdentifier; 129 | NSMutableSet *reuseSet = self.reuseViewPool[identifier]; 130 | if (!reuseSet) { 131 | reuseSet = [NSMutableSet set]; 132 | [self.reuseViewPool setValue:reuseSet forKey:identifier]; 133 | } 134 | [reuseSet addObject:view]; 135 | } 136 | 137 | - (UIView *)dequeueReusableItemWithIdentifier:(NSString *)identifier { 138 | if (!identifier) { 139 | return nil; 140 | } 141 | NSMutableSet *reuseSet = self.reuseViewPool[identifier]; 142 | UIView *view = [reuseSet anyObject]; 143 | if (view) { 144 | [reuseSet removeObject:view]; 145 | return view; 146 | } 147 | else { 148 | Class viewClass = [self.registerClass objectForKey:identifier]; 149 | view = [viewClass new]; 150 | view.reuseIdentifier = identifier; 151 | return view; 152 | } 153 | } 154 | 155 | - (void)registerClass:(Class)viewClass forViewReuseIdentifier:(NSString *)identifier { 156 | [self.registerClass setValue:viewClass forKey:identifier]; 157 | } 158 | 159 | #pragma mark - Utils 160 | 161 | - (CGFloat)minEdgeOffset { 162 | //for UIScrollView the bounds cahnge when scroll 163 | CGFloat min = CGRectGetMinY(self.bounds); 164 | return MAX(min - kBufferSize, 0); 165 | } 166 | 167 | - (CGFloat)maxEdgeOffset { 168 | //for UIScrollView the bounds cahnge when scroll 169 | CGFloat max = CGRectGetMaxY(self.bounds); 170 | return MIN(max + kBufferSize, self.contentSize.height); 171 | } 172 | 173 | - (LSVRectModel *)findFirstAscendModelWithMinEdge:(CGFloat)minEdge { 174 | // 二分法 175 | NSInteger minIndex = 0; 176 | NSInteger maxIndex = self.allAscendingRectModels.count - 1; 177 | NSInteger midIndex = (minIndex + maxIndex) / 2; 178 | LSVRectModel *model = self.allAscendingRectModels[midIndex]; 179 | 180 | while (minIndex < midIndex && midIndex < maxIndex) { 181 | if (CGRectGetMinY(model.absRect) > minEdge) { 182 | maxIndex = midIndex; 183 | } 184 | else { 185 | minIndex = midIndex; 186 | } 187 | midIndex = (minIndex + maxIndex) / 2; 188 | model = self.allAscendingRectModels[midIndex]; 189 | } 190 | 191 | //处理多个view的y值相同的情况 192 | LSVRectModel *limitModel = model; 193 | while (midIndex > 0 && CGRectGetMinY(model.absRect) == CGRectGetMinY(limitModel.absRect)) { 194 | midIndex = MAX(midIndex - 1, 0); 195 | model = self.allAscendingRectModels[midIndex]; 196 | } 197 | 198 | return model; 199 | } 200 | 201 | - (LSVRectModel *)findFirstDescendModelWithMaxEdge:(CGFloat)maxEdge { 202 | // 二分法 203 | NSInteger minIndex = 0; 204 | NSInteger maxIndex = self.allDescendingRectModels.count - 1; 205 | NSInteger midIndex = (minIndex + maxIndex) / 2; 206 | LSVRectModel *model = self.allDescendingRectModels[midIndex]; 207 | 208 | while (minIndex < midIndex && midIndex < maxIndex) { 209 | if (CGRectGetMaxY(model.absRect) < maxEdge) { 210 | maxIndex = midIndex; 211 | } 212 | else { 213 | minIndex = midIndex; 214 | } 215 | midIndex = (minIndex + maxIndex) / 2; 216 | model = self.allDescendingRectModels[midIndex]; 217 | } 218 | 219 | //处理多个view的y值相同的情况 220 | LSVRectModel *limitModel = model; 221 | while (midIndex > 0 && CGRectGetMaxY(model.absRect) == CGRectGetMaxY(limitModel.absRect)) { 222 | midIndex = MAX(midIndex - 1, 0); 223 | model = self.allDescendingRectModels[midIndex]; 224 | } 225 | 226 | return model; 227 | } 228 | 229 | - (NSArray *)getVisiableViewModels { 230 | // Descend e-----------------|s 231 | // --------------------------- Y值 232 | // s|------------e Ascend 233 | // 实际就是两个firstIndex的交叉部分 234 | LSVRectModel *firstAscendModel = [self findFirstAscendModelWithMinEdge:[self minEdgeOffset]]; 235 | LSVRectModel *firstDescendModel = [self findFirstDescendModelWithMaxEdge:[self maxEdgeOffset]]; 236 | 237 | NSInteger firstIndex = [self.allAscendingRectModels indexOfObject:firstAscendModel]; 238 | NSInteger lastIndex = [self.allAscendingRectModels indexOfObject:firstDescendModel]; 239 | 240 | return [self.allAscendingRectModels subarrayWithRange:NSMakeRange(firstIndex, lastIndex-firstIndex+1)]; 241 | } 242 | 243 | - (void)updateModelDatas { 244 | [self.allRectModels removeAllObjects]; 245 | self.allAscendingRectModels = nil; 246 | self.allDescendingRectModels = nil; 247 | 248 | _numberOfItems = [self.dataSource numberOfItemInScrollView:self]; 249 | 250 | for (NSInteger index = 0; index < _numberOfItems; ++ index) { 251 | LSVRectModel *model = [self.dataSource scrollView:self rectModelAtIndex:index]; 252 | [self.allRectModels addObject:model]; 253 | } 254 | 255 | LSVRectModel *model = self.allAscendingRectModels.lastObject; 256 | self.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), CGRectGetMaxY(model.absRect)); 257 | } 258 | 259 | - (void)handleTapAction:(UIGestureRecognizer *)gestureRecognizer { 260 | NSArray *visibleViews = [self getVisiableViewModels]; 261 | CGPoint tapPoint = [gestureRecognizer locationInView:self]; 262 | for (LSVRectModel *model in visibleViews) { 263 | if (CGRectContainsPoint(model.absRect, tapPoint)) { 264 | if ([self.delegate respondsToSelector:@selector(scrollView:didClickItemAtIndex:withLsvId:)]) { 265 | NSInteger index = [self.allRectModels indexOfObject:model]; 266 | [self.delegate scrollView:self didClickItemAtIndex:index withLsvId:model.lsvId]; 267 | } 268 | 269 | break; 270 | } 271 | } 272 | } 273 | 274 | #pragma mark - Setter 275 | 276 | - (void)setDataSource:(id)dataSource { 277 | if (dataSource != _dataSource) { 278 | _dataSource = dataSource; 279 | } 280 | if (_dataSource) { 281 | [self reloadData]; 282 | } 283 | } 284 | 285 | #pragma mark - Getter 286 | - (NSMutableDictionary *)reuseViewPool { 287 | if (!_reuseViewPool) { 288 | _reuseViewPool = [NSMutableDictionary new]; 289 | } 290 | return _reuseViewPool; 291 | } 292 | 293 | - (NSMutableArray *)allRectModels { 294 | if (!_allRectModels) { 295 | _allRectModels = [NSMutableArray new]; 296 | } 297 | return _allRectModels; 298 | } 299 | 300 | - (NSMutableArray *)allAscendingRectModels { 301 | if (!_allAscendingRectModels) { 302 | //升序 303 | _allAscendingRectModels = [[self.allRectModels 304 | sortedArrayUsingComparator:^NSComparisonResult(LSVRectModel *obj1, LSVRectModel *obj2) { 305 | CGFloat y1 = CGRectGetMaxY(obj1.absRect); CGFloat x1 = CGRectGetMinX(obj1.absRect); 306 | CGFloat y2 = CGRectGetMaxY(obj2.absRect); CGFloat x2 = CGRectGetMinX(obj2.absRect); 307 | if (y1 == y2) { 308 | return x1 <= x2 ? NSOrderedAscending: NSOrderedDescending; 309 | } else { 310 | return y1 < y2 ? NSOrderedAscending : NSOrderedDescending; 311 | } } 312 | ] mutableCopy]; 313 | } 314 | 315 | return _allAscendingRectModels; 316 | } 317 | 318 | - (NSMutableArray *)allDescendingRectModels { 319 | if (!_allDescendingRectModels) { 320 | //需要降序,而sortedArrayUsingComparator的结果是ascending order,所以block里面的结果是相反的。 321 | _allDescendingRectModels = [[self.allRectModels 322 | sortedArrayUsingComparator:^NSComparisonResult(LSVRectModel *obj1, LSVRectModel *obj2) { 323 | CGFloat y1 = CGRectGetMaxY(obj1.absRect); CGFloat x1 = CGRectGetMinX(obj1.absRect); 324 | CGFloat y2 = CGRectGetMaxY(obj2.absRect); CGFloat x2 = CGRectGetMinX(obj2.absRect); 325 | if (y1 == y2) { 326 | return x1 <= x2 ? NSOrderedDescending : NSOrderedAscending; 327 | } else { 328 | return y1 < y2 ? NSOrderedDescending : NSOrderedAscending; 329 | } 330 | } 331 | ] mutableCopy]; 332 | } 333 | 334 | return _allDescendingRectModels; 335 | } 336 | 337 | - (NSMutableDictionary *)registerClass { 338 | if (!_registerClass) { 339 | _registerClass = [NSMutableDictionary new]; 340 | } 341 | return _registerClass; 342 | } 343 | 344 | - (NSMutableSet *)visibleViews { 345 | if (!_visibleViews) { 346 | _visibleViews = [NSMutableSet set]; 347 | } 348 | return _visibleViews; 349 | } 350 | 351 | - (UITapGestureRecognizer *)tapGesture { 352 | if (!_tapGesture) { 353 | _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self 354 | action:@selector(handleTapAction:)]; 355 | } 356 | 357 | return _tapGesture; 358 | } 359 | 360 | @end 361 | 362 | 363 | #pragma mark - LSVRectModel 364 | 365 | @implementation LSVRectModel 366 | 367 | + (instancetype)modelWithRect:(CGRect)rect lsvId:(NSString *)lsvId { 368 | LSVRectModel *model = [[LSVRectModel alloc] init]; 369 | model.absRect = rect; 370 | 371 | if (lsvId.length == 0) { 372 | lsvId = NSStringFromCGRect(rect); 373 | } 374 | model.lsvId = lsvId; 375 | 376 | return model; 377 | } 378 | 379 | + (instancetype)modelWithRect:(CGRect)rect { 380 | return [self modelWithRect:rect lsvId:nil]; 381 | } 382 | 383 | @end 384 | 385 | 386 | 387 | -------------------------------------------------------------------------------- /LazyScrollView/LazyScrollView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 743FAFA91E0BBA54008097E9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 743FAFA81E0BBA54008097E9 /* main.m */; }; 11 | 743FAFAC1E0BBA54008097E9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 743FAFAB1E0BBA54008097E9 /* AppDelegate.m */; }; 12 | 743FAFAF1E0BBA54008097E9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 743FAFAE1E0BBA54008097E9 /* ViewController.m */; }; 13 | 743FAFB21E0BBA54008097E9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 743FAFB01E0BBA54008097E9 /* Main.storyboard */; }; 14 | 743FAFB41E0BBA54008097E9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 743FAFB31E0BBA54008097E9 /* Assets.xcassets */; }; 15 | 743FAFB71E0BBA54008097E9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 743FAFB51E0BBA54008097E9 /* LaunchScreen.storyboard */; }; 16 | 743FAFC11E0BBAA8008097E9 /* LazyScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 743FAFC01E0BBAA8008097E9 /* LazyScrollView.m */; }; 17 | 743FAFC41E0BBB8E008097E9 /* SingleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 743FAFC31E0BBB8E008097E9 /* SingleView.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 743FAFA41E0BBA54008097E9 /* LazyScrollView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LazyScrollView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 743FAFA81E0BBA54008097E9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 23 | 743FAFAA1E0BBA54008097E9 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 24 | 743FAFAB1E0BBA54008097E9 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 25 | 743FAFAD1E0BBA54008097E9 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 26 | 743FAFAE1E0BBA54008097E9 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 27 | 743FAFB11E0BBA54008097E9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 28 | 743FAFB31E0BBA54008097E9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29 | 743FAFB61E0BBA54008097E9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 30 | 743FAFB81E0BBA54008097E9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 743FAFBF1E0BBAA8008097E9 /* LazyScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LazyScrollView.h; sourceTree = ""; }; 32 | 743FAFC01E0BBAA8008097E9 /* LazyScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LazyScrollView.m; sourceTree = ""; }; 33 | 743FAFC21E0BBB8E008097E9 /* SingleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SingleView.h; sourceTree = ""; }; 34 | 743FAFC31E0BBB8E008097E9 /* SingleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SingleView.m; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 743FAFA11E0BBA54008097E9 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 743FAF9B1E0BBA54008097E9 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 743FAFA61E0BBA54008097E9 /* LazyScrollView */, 52 | 743FAFA51E0BBA54008097E9 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 743FAFA51E0BBA54008097E9 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 743FAFA41E0BBA54008097E9 /* LazyScrollView.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 743FAFA61E0BBA54008097E9 /* LazyScrollView */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 743FAFBE1E0BBA88008097E9 /* Classes */, 68 | 743FAFAA1E0BBA54008097E9 /* AppDelegate.h */, 69 | 743FAFAB1E0BBA54008097E9 /* AppDelegate.m */, 70 | 743FAFAD1E0BBA54008097E9 /* ViewController.h */, 71 | 743FAFAE1E0BBA54008097E9 /* ViewController.m */, 72 | 743FAFC21E0BBB8E008097E9 /* SingleView.h */, 73 | 743FAFC31E0BBB8E008097E9 /* SingleView.m */, 74 | 743FAFB01E0BBA54008097E9 /* Main.storyboard */, 75 | 743FAFB31E0BBA54008097E9 /* Assets.xcassets */, 76 | 743FAFB51E0BBA54008097E9 /* LaunchScreen.storyboard */, 77 | 743FAFB81E0BBA54008097E9 /* Info.plist */, 78 | 743FAFA71E0BBA54008097E9 /* Supporting Files */, 79 | ); 80 | path = LazyScrollView; 81 | sourceTree = ""; 82 | }; 83 | 743FAFA71E0BBA54008097E9 /* Supporting Files */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 743FAFA81E0BBA54008097E9 /* main.m */, 87 | ); 88 | name = "Supporting Files"; 89 | sourceTree = ""; 90 | }; 91 | 743FAFBE1E0BBA88008097E9 /* Classes */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 743FAFBF1E0BBAA8008097E9 /* LazyScrollView.h */, 95 | 743FAFC01E0BBAA8008097E9 /* LazyScrollView.m */, 96 | ); 97 | path = Classes; 98 | sourceTree = ""; 99 | }; 100 | /* End PBXGroup section */ 101 | 102 | /* Begin PBXNativeTarget section */ 103 | 743FAFA31E0BBA54008097E9 /* LazyScrollView */ = { 104 | isa = PBXNativeTarget; 105 | buildConfigurationList = 743FAFBB1E0BBA54008097E9 /* Build configuration list for PBXNativeTarget "LazyScrollView" */; 106 | buildPhases = ( 107 | 743FAFA01E0BBA54008097E9 /* Sources */, 108 | 743FAFA11E0BBA54008097E9 /* Frameworks */, 109 | 743FAFA21E0BBA54008097E9 /* Resources */, 110 | ); 111 | buildRules = ( 112 | ); 113 | dependencies = ( 114 | ); 115 | name = LazyScrollView; 116 | productName = LazyScrollView; 117 | productReference = 743FAFA41E0BBA54008097E9 /* LazyScrollView.app */; 118 | productType = "com.apple.product-type.application"; 119 | }; 120 | /* End PBXNativeTarget section */ 121 | 122 | /* Begin PBXProject section */ 123 | 743FAF9C1E0BBA54008097E9 /* Project object */ = { 124 | isa = PBXProject; 125 | attributes = { 126 | LastUpgradeCheck = 0810; 127 | ORGANIZATIONNAME = xiabob; 128 | TargetAttributes = { 129 | 743FAFA31E0BBA54008097E9 = { 130 | CreatedOnToolsVersion = 8.1; 131 | DevelopmentTeam = WPR8JVVW9L; 132 | ProvisioningStyle = Automatic; 133 | }; 134 | }; 135 | }; 136 | buildConfigurationList = 743FAF9F1E0BBA54008097E9 /* Build configuration list for PBXProject "LazyScrollView" */; 137 | compatibilityVersion = "Xcode 3.2"; 138 | developmentRegion = English; 139 | hasScannedForEncodings = 0; 140 | knownRegions = ( 141 | en, 142 | Base, 143 | ); 144 | mainGroup = 743FAF9B1E0BBA54008097E9; 145 | productRefGroup = 743FAFA51E0BBA54008097E9 /* Products */; 146 | projectDirPath = ""; 147 | projectRoot = ""; 148 | targets = ( 149 | 743FAFA31E0BBA54008097E9 /* LazyScrollView */, 150 | ); 151 | }; 152 | /* End PBXProject section */ 153 | 154 | /* Begin PBXResourcesBuildPhase section */ 155 | 743FAFA21E0BBA54008097E9 /* Resources */ = { 156 | isa = PBXResourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 743FAFB71E0BBA54008097E9 /* LaunchScreen.storyboard in Resources */, 160 | 743FAFB41E0BBA54008097E9 /* Assets.xcassets in Resources */, 161 | 743FAFB21E0BBA54008097E9 /* Main.storyboard in Resources */, 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXResourcesBuildPhase section */ 166 | 167 | /* Begin PBXSourcesBuildPhase section */ 168 | 743FAFA01E0BBA54008097E9 /* Sources */ = { 169 | isa = PBXSourcesBuildPhase; 170 | buildActionMask = 2147483647; 171 | files = ( 172 | 743FAFAF1E0BBA54008097E9 /* ViewController.m in Sources */, 173 | 743FAFC41E0BBB8E008097E9 /* SingleView.m in Sources */, 174 | 743FAFC11E0BBAA8008097E9 /* LazyScrollView.m in Sources */, 175 | 743FAFAC1E0BBA54008097E9 /* AppDelegate.m in Sources */, 176 | 743FAFA91E0BBA54008097E9 /* main.m in Sources */, 177 | ); 178 | runOnlyForDeploymentPostprocessing = 0; 179 | }; 180 | /* End PBXSourcesBuildPhase section */ 181 | 182 | /* Begin PBXVariantGroup section */ 183 | 743FAFB01E0BBA54008097E9 /* Main.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | 743FAFB11E0BBA54008097E9 /* Base */, 187 | ); 188 | name = Main.storyboard; 189 | sourceTree = ""; 190 | }; 191 | 743FAFB51E0BBA54008097E9 /* LaunchScreen.storyboard */ = { 192 | isa = PBXVariantGroup; 193 | children = ( 194 | 743FAFB61E0BBA54008097E9 /* Base */, 195 | ); 196 | name = LaunchScreen.storyboard; 197 | sourceTree = ""; 198 | }; 199 | /* End PBXVariantGroup section */ 200 | 201 | /* Begin XCBuildConfiguration section */ 202 | 743FAFB91E0BBA54008097E9 /* Debug */ = { 203 | isa = XCBuildConfiguration; 204 | buildSettings = { 205 | ALWAYS_SEARCH_USER_PATHS = NO; 206 | CLANG_ANALYZER_NONNULL = YES; 207 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 208 | CLANG_CXX_LIBRARY = "libc++"; 209 | CLANG_ENABLE_MODULES = YES; 210 | CLANG_ENABLE_OBJC_ARC = YES; 211 | CLANG_WARN_BOOL_CONVERSION = YES; 212 | CLANG_WARN_CONSTANT_CONVERSION = YES; 213 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 214 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 215 | CLANG_WARN_EMPTY_BODY = YES; 216 | CLANG_WARN_ENUM_CONVERSION = YES; 217 | CLANG_WARN_INFINITE_RECURSION = YES; 218 | CLANG_WARN_INT_CONVERSION = YES; 219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 220 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 221 | CLANG_WARN_UNREACHABLE_CODE = YES; 222 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 223 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 224 | COPY_PHASE_STRIP = NO; 225 | DEBUG_INFORMATION_FORMAT = dwarf; 226 | ENABLE_STRICT_OBJC_MSGSEND = YES; 227 | ENABLE_TESTABILITY = YES; 228 | GCC_C_LANGUAGE_STANDARD = gnu99; 229 | GCC_DYNAMIC_NO_PIC = NO; 230 | GCC_NO_COMMON_BLOCKS = YES; 231 | GCC_OPTIMIZATION_LEVEL = 0; 232 | GCC_PREPROCESSOR_DEFINITIONS = ( 233 | "DEBUG=1", 234 | "$(inherited)", 235 | ); 236 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 237 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 238 | GCC_WARN_UNDECLARED_SELECTOR = YES; 239 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 240 | GCC_WARN_UNUSED_FUNCTION = YES; 241 | GCC_WARN_UNUSED_VARIABLE = YES; 242 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 243 | MTL_ENABLE_DEBUG_INFO = YES; 244 | ONLY_ACTIVE_ARCH = YES; 245 | SDKROOT = iphoneos; 246 | }; 247 | name = Debug; 248 | }; 249 | 743FAFBA1E0BBA54008097E9 /* Release */ = { 250 | isa = XCBuildConfiguration; 251 | buildSettings = { 252 | ALWAYS_SEARCH_USER_PATHS = NO; 253 | CLANG_ANALYZER_NONNULL = YES; 254 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 255 | CLANG_CXX_LIBRARY = "libc++"; 256 | CLANG_ENABLE_MODULES = YES; 257 | CLANG_ENABLE_OBJC_ARC = YES; 258 | CLANG_WARN_BOOL_CONVERSION = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 261 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INFINITE_RECURSION = YES; 265 | CLANG_WARN_INT_CONVERSION = YES; 266 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 267 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 268 | CLANG_WARN_UNREACHABLE_CODE = YES; 269 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 270 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 271 | COPY_PHASE_STRIP = NO; 272 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 273 | ENABLE_NS_ASSERTIONS = NO; 274 | ENABLE_STRICT_OBJC_MSGSEND = YES; 275 | GCC_C_LANGUAGE_STANDARD = gnu99; 276 | GCC_NO_COMMON_BLOCKS = YES; 277 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 278 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 279 | GCC_WARN_UNDECLARED_SELECTOR = YES; 280 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 281 | GCC_WARN_UNUSED_FUNCTION = YES; 282 | GCC_WARN_UNUSED_VARIABLE = YES; 283 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 284 | MTL_ENABLE_DEBUG_INFO = NO; 285 | SDKROOT = iphoneos; 286 | VALIDATE_PRODUCT = YES; 287 | }; 288 | name = Release; 289 | }; 290 | 743FAFBC1E0BBA54008097E9 /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 294 | DEVELOPMENT_TEAM = WPR8JVVW9L; 295 | INFOPLIST_FILE = LazyScrollView/Info.plist; 296 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 297 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 298 | PRODUCT_BUNDLE_IDENTIFIER = xiabob.LazyScrollView; 299 | PRODUCT_NAME = "$(TARGET_NAME)"; 300 | }; 301 | name = Debug; 302 | }; 303 | 743FAFBD1E0BBA54008097E9 /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | DEVELOPMENT_TEAM = WPR8JVVW9L; 308 | INFOPLIST_FILE = LazyScrollView/Info.plist; 309 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 310 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 311 | PRODUCT_BUNDLE_IDENTIFIER = xiabob.LazyScrollView; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | }; 314 | name = Release; 315 | }; 316 | /* End XCBuildConfiguration section */ 317 | 318 | /* Begin XCConfigurationList section */ 319 | 743FAF9F1E0BBA54008097E9 /* Build configuration list for PBXProject "LazyScrollView" */ = { 320 | isa = XCConfigurationList; 321 | buildConfigurations = ( 322 | 743FAFB91E0BBA54008097E9 /* Debug */, 323 | 743FAFBA1E0BBA54008097E9 /* Release */, 324 | ); 325 | defaultConfigurationIsVisible = 0; 326 | defaultConfigurationName = Release; 327 | }; 328 | 743FAFBB1E0BBA54008097E9 /* Build configuration list for PBXNativeTarget "LazyScrollView" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 743FAFBC1E0BBA54008097E9 /* Debug */, 332 | 743FAFBD1E0BBA54008097E9 /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | /* End XCConfigurationList section */ 338 | }; 339 | rootObject = 743FAF9C1E0BBA54008097E9 /* Project object */; 340 | } 341 | --------------------------------------------------------------------------------