text
stringlengths
9
39.2M
dir
stringlengths
26
295
lang
stringclasses
185 values
created_date
timestamp[us]
updated_date
timestamp[us]
repo_name
stringlengths
1
97
repo_full_name
stringlengths
7
106
star
int64
1k
183k
len_tokens
int64
1
13.8M
```objective-c // // YNSuspendTopPausePageVC.m // YNPageViewController // // Created by ZYN on 2018/7/14. // #import "YNSuspendTopPausePageVC.h" #import "SDCycleScrollView.h" #import "BaseTableViewVC.h" #import "YNSuspendTopPauseBaseTableViewVC.h" #import "MJRefresh.h" #import "UIView+YNPageExtend.h" #define kOpenRefreshHeaderViewHeight 0 @interface YNSuspendTopPausePageVC () <YNPageViewControllerDataSource, YNPageViewControllerDelegate, SDCycleScrollViewDelegate> @property (nonatomic, copy) NSArray *imagesURLs; @end @implementation YNSuspendTopPausePageVC - (void)viewDidLoad { [super viewDidLoad]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // [self.navigationController setNavigationBarHidden:NO animated:animated]; } #pragma mark - Event Response #pragma mark - --Notification Event Response #pragma mark - --Button Event Response #pragma mark - --Gesture Event Response #pragma mark - System Delegate #pragma mark - Custom Delegate #pragma mark - Public Function + (instancetype)suspendTopPausePageVC { YNPageConfigration *configration = [YNPageConfigration defaultConfig]; configration.pageStyle = YNPageStyleSuspensionTopPause; configration.headerViewCouldScale = YES; configration.showTabbar = NO; configration.showNavigation = YES; configration.scrollMenu = NO; configration.aligmentModeCenter = NO; configration.lineWidthEqualFontWidth = NO; configration.showBottomLine = YES; YNSuspendTopPausePageVC *vc = [YNSuspendTopPausePageVC pageViewControllerWithControllers:[self getArrayVCs] titles:[self getArrayTitles] config:configration]; vc.dataSource = vc; vc.delegate = vc; UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, YFScreen.width, YFScreen.height)]; headerView.layer.contents = (id)[UIImage imageNamed:@"mine_header_bg"].CGImage; /// SDCycleScrollView *autoScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, YFScreen.width, 200) imageURLStringsGroup:vc.imagesURLs]; autoScrollView.delegate = vc; vc.headerView = autoScrollView; // vc.headerView = headerView; /// index vc.pageIndex = 1; __weak typeof(YNSuspendTopPausePageVC *) weakVC = vc; vc.bgScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ NSInteger refreshPage = weakVC.pageIndex; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ /// pageIndex YNSuspendTopPauseBaseTableViewVC *vc2 = weakVC.controllersM[refreshPage]; [vc2.tableView reloadData]; if (kOpenRefreshHeaderViewHeight) { weakVC.headerView.yn_height = 300; [weakVC.bgScrollView.mj_header endRefreshing]; [weakVC reloadSuspendHeaderViewFrame]; } else { [weakVC.bgScrollView.mj_header endRefreshing]; } }); }]; return vc; } + (NSArray *)getArrayVCs { YNSuspendTopPauseBaseTableViewVC *vc_1 = [[YNSuspendTopPauseBaseTableViewVC alloc] init]; vc_1.cellTitle = @""; YNSuspendTopPauseBaseTableViewVC *vc_2 = [[YNSuspendTopPauseBaseTableViewVC alloc] init]; vc_2.cellTitle = @""; YNSuspendTopPauseBaseTableViewVC *vc_3 = [[YNSuspendTopPauseBaseTableViewVC alloc] init]; vc_3.cellTitle = @""; return @[vc_1, vc_2, vc_3]; } + (NSArray *)getArrayTitles { return @[@"", @"", @""]; } #pragma mark - Private Function #pragma mark - Getter and Setter - (NSArray *)imagesURLs { if (!_imagesURLs) { _imagesURLs = @[ @"path_to_url", @"path_to_url", @"path_to_url"]; } return _imagesURLs; } #pragma mark - YNPageViewControllerDataSource - (UIScrollView *)pageViewController:(YNPageViewController *)pageViewController pageForIndex:(NSInteger)index { UIViewController *vc = pageViewController.controllersM[index]; return [(YNSuspendTopPauseBaseTableViewVC *)vc tableView]; } #pragma mark - YNPageViewControllerDelegate - (void)pageViewController:(YNPageViewController *)pageViewController contentOffsetY:(CGFloat)contentOffset progress:(CGFloat)progress { NSLog(@"--- contentOffset = %f, progress = %f", contentOffset, progress); } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { NSLog(@"----click index %ld", index); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/SuspendTopPausePageVC/YNSuspendTopPausePageVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,125
```objective-c // // BaseVC.m // YNPageViewController // // Created by ZYN on 2018/6/22. // #import "BaseTableViewVC.h" #import "MJRefresh.h" #import "BaseViewController.h" #import "UIViewController+YNPageExtend.h" /// #define kOpenRefreshHeaderViewHeight 0 #define kCellHeight 44 @interface BaseTableViewVC () <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, strong) NSMutableArray *dataArray; /// cell @property (nonatomic, assign) CGFloat placeHolderCellHeight; @end @implementation BaseTableViewVC - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"id"]; [self.view addSubview:self.tableView]; _dataArray = @[].mutableCopy; /// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (int i = 0; i < 30; i++) { [_dataArray addObject:@""]; } [self.tableView reloadData]; }); [self addTableViewRefresh]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [self.tableView.mj_header beginRefreshing]; // }); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } /// - (void)addTableViewRefresh { __weak typeof (self) weakSelf = self; self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (int i = 0; i < 3; i++) { [weakSelf.dataArray addObject:@""]; } [weakSelf.tableView reloadData]; if (kOpenRefreshHeaderViewHeight) { [weakSelf suspendTopReloadHeaderViewHeight]; } else { [weakSelf.tableView.mj_header endRefreshing]; } }); }]; self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (int i = 0; i < 3; i++) { [weakSelf.dataArray addObject:@""]; } [weakSelf.tableView reloadData]; [weakSelf.tableView.mj_footer endRefreshing]; }); }]; } #pragma mark - Center - (void)suspendTopReloadHeaderViewHeight { /// CGFloat netWorkHeight = 300; __weak typeof (self) weakSelf = self; /// HeaderView [self.tableView.mj_header endRefreshingWithCompletionBlock:^{ YNPageViewController *VC = weakSelf.yn_pageViewController; if (VC.headerView.frame.size.height != netWorkHeight) { VC.headerView.frame = CGRectMake(0, 0, YFScreen.width, netWorkHeight); [VC reloadSuspendHeaderViewFrame]; } }]; } #pragma mark - cell - (CGFloat)placeHolderCellHeight { CGFloat height = self.config.contentHeight - kCellHeight * self.dataArray.count; height = height < 0 ? 0 : height; return height; } #pragma mark - UITableViewDelegate UITableViewDataSource - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.00001; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [UIView new]; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.00001; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count + 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row < self.dataArray.count) { return kCellHeight; } return self.placeHolderCellHeight; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id"]; if (indexPath.row < self.dataArray.count) { cell.textLabel.text = [NSString stringWithFormat:@"%@ section: %zd row:%zd", self.cellTitle ?: @"", indexPath.section, indexPath.row]; return cell; } else { cell.textLabel.text = @""; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { BaseViewController *baseVC = [BaseViewController new]; baseVC.title = @""; [self.navigationController pushViewController:baseVC animated:YES]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; } return _tableView; } - (void)dealloc { NSLog(@"----- %@ delloc", self.class); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/BaseVC/BaseTableViewVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,234
```objective-c // // YNSuspendTopPausePageVC.h // YNPageViewController // // Created by ZYN on 2018/7/14. // #import "BasePageViewController.h" @interface YNSuspendTopPausePageVC : BasePageViewController + (instancetype)suspendTopPausePageVC; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/SuspendTopPausePageVC/YNSuspendTopPausePageVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
69
```objective-c // // YNSuspendTopPauseBaseTableViewVC.h // YNPageViewController // // Created by ZYN on 2018/7/14. // #import <UIKit/UIKit.h> @interface YNSuspendTopPauseBaseTableViewVC : UIViewController @property (nonatomic, copy) NSString *cellTitle; @property (nonatomic, strong) UITableView *tableView; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/SuspendTopPausePageVC/YNSuspendTopPauseBaseTableViewVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
79
```objective-c // // ScrollMenuStyleVC.h // YNPageViewController // // Created by ZYN on 2018/6/25. // #import <UIKit/UIKit.h> @interface YNScrollMenuStyleVC : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/ScrollMenuStyleVC/YNScrollMenuStyleVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // YNSuspendTopPauseBaseTableViewVC.m // YNPageViewController // // Created by ZYN on 2018/7/14. // #import "YNSuspendTopPauseBaseTableViewVC.h" #import "MJRefresh.h" #import "BaseViewController.h" #import "UIViewController+YNPageExtend.h" #import "YNPageTableView.h" #define kCellHeight 44 @interface YNSuspendTopPauseBaseTableViewVC () <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, strong) NSMutableArray *dataArray; @end @implementation YNSuspendTopPauseBaseTableViewVC - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"id"]; [self.view addSubview:self.tableView]; _dataArray = @[].mutableCopy; /// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (int i = 0; i < 420; i++) { [_dataArray addObject:@""]; } [self.tableView reloadData]; }); [self addTableViewRefresh]; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [self.tableView setContentOffset:CGPointMake(0, 240)]; // }); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; NSLog(@"--%@--%@", [self class], NSStringFromSelector(_cmd)); } - (void)addTableViewRefresh { __weak typeof (self) weakSelf = self; /// footer self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (int i = 0; i < 30; i++) { [weakSelf.dataArray addObject:@""]; } [weakSelf.tableView reloadData]; [weakSelf.tableView.mj_footer endRefreshing]; }); }]; } #pragma mark - UITableViewDelegate UITableViewDataSource - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.00001; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [UIView new]; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.00001; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row < self.dataArray.count) { return kCellHeight; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id"]; if (indexPath.row < self.dataArray.count) { cell.textLabel.text = [NSString stringWithFormat:@"%@ section: %zd row:%zd", self.cellTitle ?: @"", indexPath.section, indexPath.row]; return cell; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { BaseViewController *baseVC = [BaseViewController new]; baseVC.title = @""; [self.navigationController pushViewController:baseVC animated:YES]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[YNPageTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; } return _tableView; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/SuspendTopPausePageVC/YNSuspendTopPauseBaseTableViewVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
930
```objective-c // // YNNavPageVC.h // YNPageViewController // // Created by ZYN on 2018/6/22. // #import "BasePageViewController.h" @interface YNNavPageVC : BasePageViewController + (instancetype)navPageVC; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/NavPageVC/YNNavPageVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
63
```objective-c // // ScrollMenuStyleVC.m // YNPageViewController // // Created by ZYN on 2018/6/25. // #import "YNScrollMenuStyleVC.h" #import "YNPageScrollMenuView.h" #import "YNPageConfigration.h" #import "UIView+YNPageExtend.h" @interface YNScrollMenuStyleVC ()<YNPageScrollMenuViewDelegate> @property (nonatomic, strong) UIScrollView *scrollView; @end @implementation YNScrollMenuStyleVC - (void)viewDidLoad { [super viewDidLoad]; _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, YFScreen.width, self.view.frame.size.height)]; _scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor]; /// style 1 YNPageConfigration *style_config_1 = [YNPageConfigration defaultConfig]; YNPageScrollMenuView *style_1 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, 0, YFScreen.width, 44) titles:@[@"JAVA", @"Object-C", @"JS"].mutableCopy configration:style_config_1 delegate:self currentIndex:0]; /// style 2 YNPageConfigration *style_config_2 = [YNPageConfigration defaultConfig]; style_config_2.showBottomLine = YES; style_config_2.bottomLineBgColor = [UIColor greenColor]; style_config_2.bottomLineHeight = 1; YNPageScrollMenuView *style_2 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, style_1.yn_bottom + 20, YFScreen.width, 44) titles:@[@"", @"", @"", @"", @"QQ", @"QQ", @""].mutableCopy configration:style_config_2 delegate:self currentIndex:0]; /// style 3 YNPageConfigration *style_config_3 = [YNPageConfigration defaultConfig]; style_config_3.showBottomLine = YES; style_config_3.bottomLineBgColor = [UIColor greenColor]; style_config_3.bottomLineHeight = 1; style_config_3.scrollMenu = NO; style_config_3.aligmentModeCenter = NO; style_config_3.lineWidthEqualFontWidth = NO; style_config_3.showBottomLine = YES; style_config_3.itemFont = [UIFont systemFontOfSize:14]; style_config_3.selectedItemColor = [UIColor redColor]; style_config_3.normalItemColor = [UIColor blackColor]; YNPageScrollMenuView *style_3 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, style_2.yn_bottom + 20, YFScreen.width, 44) titles:@[@"QQ", @"QQ", @""].mutableCopy configration:style_config_3 delegate:self currentIndex:0]; /// style 4 YNPageConfigration *style_config_4 = [YNPageConfigration defaultConfig]; style_config_4.converColor = [UIColor grayColor]; style_config_4.showConver = YES; style_config_4.itemFont = [UIFont systemFontOfSize:14]; style_config_4.selectedItemColor = [UIColor redColor]; style_config_4.normalItemColor = [UIColor blackColor]; style_config_4.itemMaxScale = 1.3; YNPageScrollMenuView *style_4 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, style_3.yn_bottom + 20, YFScreen.width, 44) titles:@[@"QQ", @"QQ", @""].mutableCopy configration:style_config_4 delegate:self currentIndex:2]; /// style 5 YNPageConfigration *style_config_5 = [YNPageConfigration defaultConfig]; style_config_5.selectedItemColor = [UIColor redColor]; style_config_5.selectedItemFont = [UIFont systemFontOfSize:15]; YNPageScrollMenuView *style_5 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, style_4.yn_bottom + 20, YFScreen.width, 44) titles:@[@"JAVA", @"Object-C", @"JS"].mutableCopy configration:style_config_5 delegate:self currentIndex:1]; /// style 6 YNPageConfigration *style_config_6 = [YNPageConfigration defaultConfig]; style_config_6.scrollMenu = YES; style_config_6.aligmentModeCenter = NO; YNPageScrollMenuView *style_6 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, style_5.yn_bottom + 20, YFScreen.width, 44) titles:@[@"JAVA", @"Object-C", @"JS"].mutableCopy configration:style_config_6 delegate:self currentIndex:1]; /// style 7 YNPageConfigration *style_config_7 = [YNPageConfigration defaultConfig]; style_config_7.scrollMenu = NO; style_config_7.aligmentModeCenter = NO; NSMutableArray *buttonArrayM = @[].mutableCopy; for (int i = 0; i < 3; i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"small_icon"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"icon_back_small_black"] forState:UIControlStateSelected]; /// seTitle -> sizeToFit -> /// button.imageEdgeInsets = UIEdgeInsetsMake(0, 100, 0, 0); [buttonArrayM addObject:button]; } style_config_7.buttonArray = buttonArrayM; YNPageScrollMenuView *style_7 = [YNPageScrollMenuView pagescrollMenuViewWithFrame:CGRectMake(0, style_6.yn_bottom + 20, YFScreen.width, 44) titles:@[@"iCON", @"", @""].mutableCopy configration:style_config_7 delegate:self currentIndex:1]; [_scrollView addSubview:style_1]; [_scrollView addSubview:style_2]; [_scrollView addSubview:style_3]; [_scrollView addSubview:style_4]; [_scrollView addSubview:style_5]; [_scrollView addSubview:style_6]; [_scrollView addSubview:style_7]; [self.view addSubview:_scrollView]; } /// item - (void)pagescrollMenuViewItemOnClick:(UIButton *)label index:(NSInteger)index { NSLog(@"button = %@, index = %ld", label.titleLabel.text, (long)index); } /// Add - (void)pagescrollMenuViewAddButtonAction:(UIButton *)button { NSLog(@"button = %@", button.titleLabel.text); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/ScrollMenuStyleVC/YNScrollMenuStyleVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,448
```objective-c // // YNNavPageVC.m // YNPageViewController // // Created by ZYN on 2018/6/22. // #import "YNNavPageVC.h" #import "BaseTableViewVC.h" @interface YNNavPageVC () <YNPageViewControllerDelegate, YNPageViewControllerDataSource> @end @implementation YNNavPageVC - (void)viewDidLoad { [super viewDidLoad]; } + (instancetype)navPageVC { YNPageConfigration *configration = [YNPageConfigration defaultConfig]; configration.pageStyle = YNPageStyleNavigation; configration.headerViewCouldScale = YES; configration.headerViewScaleMode = YNPageHeaderViewScaleModeTop; configration.showTabbar = NO; configration.showNavigation = YES; configration.scrollMenu = NO; configration.aligmentModeCenter = NO; configration.lineWidthEqualFontWidth = NO; configration.showBottomLine = YES; /// configration.menuWidth = 150; YNNavPageVC *vc = [YNNavPageVC pageViewControllerWithControllers:[self getArrayVCs] titles:[self getArrayTitles] config:configration]; vc.dataSource = vc; vc.delegate = vc; return vc; } + (NSArray *)getArrayVCs { BaseTableViewVC *vc_1 = [[BaseTableViewVC alloc] init]; vc_1.cellTitle = @""; BaseTableViewVC *vc_2 = [[BaseTableViewVC alloc] init]; vc_2.cellTitle = @""; BaseTableViewVC *vc_3 = [[BaseTableViewVC alloc] init]; vc_3.cellTitle = @""; return @[vc_1, vc_2, vc_3]; } + (NSArray *)getArrayTitles { return @[@"", @"", @"3"]; } #pragma mark - YNPageViewControllerDataSource - (UIScrollView *)pageViewController:(YNPageViewController *)pageViewController pageForIndex:(NSInteger)index { BaseTableViewVC *baseVC = pageViewController.controllersM[index]; return [baseVC tableView]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/NavPageVC/YNNavPageVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
458
```objective-c // // LoadPageVC.h // YNPageViewController // // Created by ZYN on 2018/6/26. // #import "BaseViewController.h" @interface YNLoadPageVC : BaseViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/LoadPageVC/YNLoadPageVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // YNTopPageVC.h // YNPageViewController // // Created by ZYN on 2018/6/22. // #import "BasePageViewController.h" @interface YNTopPageVC : BasePageViewController + (instancetype)topPageVC; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/TopPageVC/YNTopPageVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
63
```objective-c // // LoadPageVC.m // YNPageViewController // // Created by ZYN on 2018/6/26. // #import "YNLoadPageVC.h" #import "YNPageViewController.h" #import "YNSuspendCenterPageVC.h" #import "YNTopPageVC.h" #import "UIView+YNPageExtend.h" /// #define kHiddenNavigationBar 1 @interface YNLoadPageVC () @property (nonatomic, strong) UIActivityIndicatorView *indicatorView; @end @implementation YNLoadPageVC - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (kHiddenNavigationBar) { [self.navigationController setNavigationBarHidden:YES animated:animated]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (kHiddenNavigationBar) { [self.navigationController setNavigationBarHidden:NO animated:animated]; } } - (void)viewDidLoad { [super viewDidLoad]; _indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; _indicatorView.frame = CGRectMake(0, 0, 80, 80); _indicatorView.center = self.view.center; [_indicatorView startAnimating]; /// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self setupPageVC]; [_indicatorView stopAnimating]; [_indicatorView setHidden:YES]; }); [self.view addSubview:_indicatorView]; } - (void)setupPageVC { YNPageConfigration *configration = [YNPageConfigration defaultConfig]; configration.pageStyle = YNPageStyleSuspensionCenter; configration.headerViewCouldScale = YES; // configration.headerViewScaleMode = YNPageHeaderViewScaleModeCenter; configration.headerViewScaleMode = YNPageHeaderViewScaleModeTop; /// tabbar nav configration.showTabbar = NO; configration.showNavigation = NO; configration.scrollMenu = NO; configration.aligmentModeCenter = NO; configration.lineWidthEqualFontWidth = NO; configration.showBottomLine = YES; configration.suspenOffsetY = 64; YNSuspendCenterPageVC *pageVC = [YNSuspendCenterPageVC suspendCenterPageVCWithConfig:configration]; /// [pageVC addSelfToParentViewController:self]; /// y if (kHiddenNavigationBar) { // pageVC.view.yn_y = kYNPAGE_NAVHEIGHT; } } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/LoadPageVC/YNLoadPageVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
558
```objective-c // // YNSuspendCustomNavOrSuspendPositionVC.h // YNPageViewController // // Created by ZYN on 2018/7/19. // #import "BaseViewController.h" @interface YNSuspendCustomNavOrSuspendPositionVC : BaseViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/SuspendCustomNavOrSuspendPositionVC/YNSuspendCustomNavOrSuspendPositionVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
63
```objective-c // // YNTopPageVC.m // YNPageViewController // // Created by ZYN on 2018/6/22. // #import "YNTopPageVC.h" #import "BaseTableViewVC.h" @interface YNTopPageVC () <YNPageViewControllerDelegate, YNPageViewControllerDataSource> @end @implementation YNTopPageVC - (void)viewDidLoad { [super viewDidLoad]; } + (instancetype)topPageVC { YNPageConfigration *configration = [YNPageConfigration defaultConfig]; configration.pageStyle = YNPageStyleTop; configration.headerViewCouldScale = YES; configration.headerViewScaleMode = YNPageHeaderViewScaleModeTop; configration.showTabbar = NO; configration.showNavigation = YES; configration.scrollMenu = NO; configration.aligmentModeCenter = NO; configration.lineWidthEqualFontWidth = NO; configration.showBottomLine = YES; YNTopPageVC *vc = [YNTopPageVC pageViewControllerWithControllers:[self getArrayVCs] titles:[self getArrayTitles] config:configration]; vc.dataSource = vc; vc.delegate = vc; return vc; } + (NSArray *)getArrayVCs { BaseTableViewVC *vc_1 = [[BaseTableViewVC alloc] init]; vc_1.cellTitle = @""; BaseTableViewVC *vc_2 = [[BaseTableViewVC alloc] init]; vc_2.cellTitle = @""; BaseTableViewVC *vc_3 = [[BaseTableViewVC alloc] init]; vc_3.cellTitle = @""; return @[vc_1, vc_2, vc_3]; } + (NSArray *)getArrayTitles { return @[@"", @"", @""]; } #pragma mark - YNPageViewControllerDataSource - (UIScrollView *)pageViewController:(YNPageViewController *)pageViewController pageForIndex:(NSInteger)index { BaseTableViewVC *baseVC = pageViewController.controllersM[index]; return [baseVC tableView]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/TopPageVC/YNTopPageVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
444
```objective-c // // YFStackedPageVC.m // BigShow1949 // // Created by zhht01 on 16/3/16. // #import "YFStackedPageVC.h" #import "SSStackedPageView.h" #import "UIColor+CatColors.h" @interface YFStackedPageVC () <SSStackedViewDelegate> @property (nonatomic) IBOutlet SSStackedPageView *stackView; @property (nonatomic) NSMutableArray *views; @end @implementation YFStackedPageVC - (void)viewDidLoad { [super viewDidLoad]; self.stackView.delegate = self; self.stackView.pagesHaveShadows = YES; self.views = [[NSMutableArray alloc] init]; for (int i = 0; i < 5; i++) { UIView *thisView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 200.f, 100.f)]; [self.views addObject:thisView]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - SSStackedViewDelegate // - (UIView *)stackView:(SSStackedPageView *)stackView pageForIndex:(NSInteger)index { UIView *thisView = [stackView dequeueReusablePage]; if (!thisView) { thisView = [self.views objectAtIndex:index]; thisView.backgroundColor = [UIColor getRandomColor]; thisView.layer.cornerRadius = 5; thisView.layer.masksToBounds = YES; } return thisView; } // - (NSInteger)numberOfPagesForStackView:(SSStackedPageView *)stackView { return [self.views count]; } // - (void)stackView:(SSStackedPageView *)stackView selectedPageAtIndex:(NSInteger) index { NSLog(@"selected page: %i",(int)index); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/StackedPageVC/YFStackedPageVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
400
```objective-c // // UIColor+CatColors.m // Categories Demo // // Created by Stevenson on 1/20/14. // #import "UIColor+CatColors.h" @implementation UIColor (CatColors) +(UIColor *) tanColor { return [UIColor colorWithRed:225.f/255.f green:166.f/255.f blue:166.f/255.f alpha:1.f]; } +(UIColor *) getRandomColor { //CGFloat r = drand48(255)/255; NSMutableArray *comps = [NSMutableArray new]; for (int i=0;i<3;i++) { NSUInteger r = arc4random_uniform(256); CGFloat randomColorComponent = (CGFloat)r/255.f; [comps addObject:@(randomColorComponent)]; } return [UIColor colorWithRed:[comps[0] floatValue] green:[comps[1] floatValue] blue:[comps[2] floatValue] alpha:1.0]; } -(UIColor *)makeGreenest{ CGFloat r,g,b,a; [self getRed:&r green:&g blue:&b alpha:&a]; return [UIColor colorWithRed:r green:1.0 blue:b alpha:a]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/StackedPageVC/UIColor+CatColors.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
249
```objective-c // // SSStackView.h // SSStackView // // Created by Stevenson on 3/10/14. // #import <UIKit/UIKit.h> @protocol SSStackedViewDelegate; @interface SSStackedPageView : UIView<UIScrollViewDelegate> ///delegate @property (nonatomic) id<SSStackedViewDelegate> delegate; ///user settings for pages to have shadows @property (nonatomic) BOOL pagesHaveShadows; ///dequeue the last page in the reusable queue - (UIView*)dequeueReusablePage; @end @protocol SSStackedViewDelegate ///method for setting the current page at the index - (UIView*)stackView:(SSStackedPageView *)stackView pageForIndex:(NSInteger)index; ///total number of pages to present in the stack - (NSInteger)numberOfPagesForStackView:(SSStackedPageView *)stackView; ///handler for when a page is selected - (void)stackView:(SSStackedPageView *)stackView selectedPageAtIndex:(NSInteger) index; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/StackedPageVC/SSStackedPageView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
215
```objective-c // // UIColor+CatColors.h // Categories Demo // // Created by Stevenson on 1/20/14. // #import <UIKit/UIKit.h> @interface UIColor (CatColors) +(UIColor *)tanColor ; +(UIColor *) getRandomColor; -(UIColor*) makeGreenest; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/StackedPageVC/UIColor+CatColors.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
63
```objective-c // // YNSuspendCustomNavOrSuspendPositionVC.m // YNPageViewController // // Created by ZYN on 2018/7/19. // #import "YNSuspendCustomNavOrSuspendPositionVC.h" #import "YNPageViewController.h" #import "UIView+YNPageExtend.h" #import "BaseTableViewVC.h" #import "BaseCollectionViewVC.h" #import "SDCycleScrollView.h" #import "UIColor+Extension.h" @interface YNSuspendCustomNavOrSuspendPositionVC () <YNPageViewControllerDataSource, YNPageViewControllerDelegate, SDCycleScrollViewDelegate> @property (nonatomic, strong) UIActivityIndicatorView *indicatorView; @property (nonatomic, copy) NSArray *imagesURLs; @property (nonatomic, strong) UIView *navView; @end @implementation YNSuspendCustomNavOrSuspendPositionVC - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; } - (void)viewDidLoad { [super viewDidLoad]; _indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; _indicatorView.frame = CGRectMake(0, 0, 80, 80); _indicatorView.center = self.view.center; [_indicatorView startAnimating]; /// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self setupPageVC]; [_indicatorView stopAnimating]; [_indicatorView setHidden:YES]; }); [self.view addSubview:_indicatorView]; } - (void)setupPageVC { YNPageConfigration *configration = [YNPageConfigration defaultConfig]; configration.pageStyle = YNPageStyleSuspensionCenter; configration.headerViewCouldScale = YES; /// tabbar nav configration.showTabbar = NO; configration.showNavigation = NO; configration.scrollMenu = NO; configration.aligmentModeCenter = NO; configration.lineWidthEqualFontWidth = NO; configration.showBottomLine = YES; /// configration.suspenOffsetY = kYNPAGE_NAVHEIGHT; YNPageViewController *vc = [YNPageViewController pageViewControllerWithControllers:self.getArrayVCs titles:[self getArrayTitles] config:configration]; vc.dataSource = self; vc.delegate = self; /// YFScreen.width SDCycleScrollView *autoScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, YFScreen.width, 200) imageURLStringsGroup:self.imagesURLs]; autoScrollView.delegate = self; vc.headerView = autoScrollView; /// index vc.pageIndex = 2; /// [vc addSelfToParentViewController:self]; /// y // pageVC.view.yn_y = kYNPAGE_NAVHEIGHT; [self.view addSubview:self.navView]; } - (NSArray *)getArrayVCs { BaseTableViewVC *vc_1 = [[BaseTableViewVC alloc] init]; vc_1.cellTitle = @""; BaseTableViewVC *vc_2 = [[BaseTableViewVC alloc] init]; vc_2.cellTitle = @""; BaseCollectionViewVC *vc_3 = [[BaseCollectionViewVC alloc] init]; return @[vc_1, vc_2, vc_3]; } - (NSArray *)getArrayTitles { return @[@"", @"", @""]; } - (UIView *)navView { if (!_navView) { _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, YFScreen.width, kYNPAGE_NAVHEIGHT)]; // _navView.backgroundColor = RGB_COLOR(246, 246, 246, 0); } return _navView; } #pragma mark - Private Function #pragma mark - Getter and Setter - (NSArray *)imagesURLs { if (!_imagesURLs) { _imagesURLs = @[ @"path_to_url", @"path_to_url", @"path_to_url"]; } return _imagesURLs; } #pragma mark - YNPageViewControllerDataSource - (UIScrollView *)pageViewController:(YNPageViewController *)pageViewController pageForIndex:(NSInteger)index { UIViewController *vc = pageViewController.controllersM[index]; if ([vc isKindOfClass:[BaseTableViewVC class]]) { return [(BaseTableViewVC *)vc tableView]; } else { return [(BaseCollectionViewVC *)vc collectionView]; } } #pragma mark - YNPageViewControllerDelegate - (void)pageViewController:(YNPageViewController *)pageViewController contentOffsetY:(CGFloat)contentOffset progress:(CGFloat)progress { NSLog(@"--- contentOffset = %f, progress = %f", contentOffset, progress); // self.navView.backgroundColor = RGBA(246, 246, 246, progress); } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { NSLog(@"----click index %ld", index); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/YNPageView/Demos/SuspendCustomNavOrSuspendPositionVC/YNSuspendCustomNavOrSuspendPositionVC.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,127
```objective-c // // YFStackedPageVC.h // BigShow1949 // // Created by zhht01 on 16/3/16. // #import <UIKit/UIKit.h> @interface YFStackedPageVC : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/StackedPageVC/YFStackedPageVC.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
54
```objective-c // // WSFSlideTitlesView.h // WSFSlideTitlesView // // Created by WangShengFeng on 3/7/16. // #import <UIKit/UIKit.h> @class WSFSlideTitlesView; @class WSFSlideTitlesViewSetting; @protocol WSFSlideTitlesViewDelegate <NSObject> @optional // - (void)slideTitlesView:(WSFSlideTitlesView *)titlesView didSelectButton:(UIButton *)button atIndex:(NSUInteger)index; @end @interface WSFSlideTitlesView : UIView @property (nonatomic, weak) id<WSFSlideTitlesViewDelegate> delegate; // + (instancetype)slideTitlesViewWithSetting:(WSFSlideTitlesViewSetting *)setting; - (instancetype)initWithSetting:(WSFSlideTitlesViewSetting *)setting; // - (void)selectButtonAtIndex:(NSUInteger)index; @end @interface WSFSlideTitlesViewSetting : NSObject #pragma mark // @property (nonatomic, strong) NSArray *titlesArr; // @property (nonatomic, strong) NSArray *selectedTitlesArr; // view @property (nonatomic, assign) CGRect frame; // view @property (nonatomic, strong) UIColor *backgroundColor; // @property (nonatomic, strong) UIColor *textColor; // @property (nonatomic, strong) UIColor *selectedTextColor; // @property (nonatomic, assign) CGFloat textFontSize; // @property (nonatomic, assign) CGFloat selectedTextFontSize; #pragma mark // @property (nonatomic, assign) BOOL lineHidden; // @property (nonatomic, assign) CGFloat lineWidth; // 1 @property (nonatomic, assign) CGFloat lineHeight; // @property (nonatomic, strong) UIColor *lineColor; // 1 @property (nonatomic, assign) CGFloat lineBottomSpace; // 0.5 @property (nonatomic, assign) NSTimeInterval animateDuration; @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/SlideTitlesView/WSFSlideTitlesView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
408
```objective-c // // SSStackView.m // SSStackView // // Created by Stevenson on 3/10/14. // #import "SSStackedPageView.h" #define OFFSET_TOP 30.f #define PAGE_PEAK 50.f #define MINIMUM_ALPHA 0.5f #define MINIMUM_SCALE 0.9f #define TOP_OFFSET_HIDE 20.f #define BOTTOM_OFFSET_HIDE 20.f #define COLLAPSED_OFFSET 5.f #define SHADOW_VECTOR CGSizeMake(0.f,-.5f) #define SHADOW_ALPHA .3f @interface SSStackedPageView() ///ScrollView attached to this view @property (nonatomic) UIScrollView *theScrollView; ///array containing reusable pages @property (nonatomic) NSMutableArray *reusablePages; ///index of the current page selected @property (nonatomic) NSInteger selectedPageIndex; ///tracked translation for the current view being dragged @property (nonatomic) CGFloat trackedTranslation; //count of the total number of pages @property (nonatomic) NSInteger pageCount; ///array of the posts contained @property (nonatomic) NSMutableArray *pages; ///current posts visible @property (nonatomic) NSRange visiblePages; @end @implementation SSStackedPageView - (void)awakeFromNib { [super awakeFromNib]; [self setup]; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; if (self.delegate) { self.pageCount = [self.delegate numberOfPagesForStackView:self]; } [self.reusablePages removeAllObjects]; self.visiblePages = NSMakeRange(0, 0); for (NSInteger i=0; i < [self.pages count]; i++) { [self removePageAtIndex:i]; } [self.pages removeAllObjects]; for (NSInteger i=0; i<self.pageCount; i++) { [self.pages addObject:[NSNull null]]; } self.theScrollView.frame = CGRectMake(0.f, 0.f, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)); self.theScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds), MAX(CGRectGetHeight(self.bounds), OFFSET_TOP+self.pageCount * PAGE_PEAK)); [self addSubview:self.theScrollView]; [self setPageAtOffset:self.theScrollView.contentOffset]; [self reloadVisiblePages]; } #pragma mark - setup methods - (void)setup { self.pageCount = 0; self.selectedPageIndex = -1; self.pages = [[NSMutableArray alloc] init]; self.reusablePages = [[NSMutableArray alloc] init]; self.visiblePages = NSMakeRange(0, 0); NSLog(@"bounds = %@", NSStringFromCGRect(self.bounds)); self.theScrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; self.theScrollView.delegate = self; self.theScrollView.backgroundColor = [UIColor clearColor]; self.theScrollView.showsVerticalScrollIndicator = NO; } #pragma mark - Page Selection - (void)selectPageAtIndex:(NSInteger)index { if (index != self.selectedPageIndex) { self.selectedPageIndex = index; NSInteger visibleEnd = self.visiblePages.location + self.visiblePages.length; [self hidePagesBehind:NSMakeRange(self.visiblePages.location, index-self.visiblePages.location)]; if (index+1 < visibleEnd) { NSInteger start = index+1; NSInteger stop = visibleEnd-start; [self hidePagesInFront:NSMakeRange(start,stop)]; } self.theScrollView.scrollEnabled = NO; } else { self.selectedPageIndex = -1; [self resetPages]; } } - (void)resetPages { NSInteger start = self.visiblePages.location; NSInteger stop = self.visiblePages.location + self.visiblePages.length; [UIView beginAnimations:@"stackReset" context:nil]; [UIView setAnimationDuration:.4f]; for (NSInteger i=start;i < stop;i++) { UIView *page = [self.pages objectAtIndex:i]; page.layer.transform = CATransform3DMakeScale(MINIMUM_SCALE, MINIMUM_SCALE, 1.f); CGRect thisFrame = page.frame; thisFrame.origin.y = OFFSET_TOP + i * PAGE_PEAK; page.frame = thisFrame; } [UIView commitAnimations]; self.theScrollView.scrollEnabled = YES; } - (void)hidePagesBehind:(NSRange)backPages { NSInteger start = backPages.location; NSInteger stop = backPages.location + backPages.length; [UIView beginAnimations:@"stackHideBack" context:nil]; [UIView setAnimationDuration:.4f]; for (NSInteger i=start;i <= stop;i++) { UIView *page = (UIView*)[self.pages objectAtIndex:i]; CGRect thisFrame = page.frame; NSInteger visibleIndex = i-self.visiblePages.location; thisFrame.origin.y = self.theScrollView.contentOffset.y+TOP_OFFSET_HIDE + visibleIndex * COLLAPSED_OFFSET; page.frame = thisFrame; } [UIView commitAnimations]; } - (void)hidePagesInFront:(NSRange)frontPages { NSInteger start = frontPages.location; NSInteger stop = frontPages.location + frontPages.length; [UIView beginAnimations:@"stackHideFront" context:nil]; [UIView setAnimationDuration:.4f]; for (NSInteger i=start;i < stop;i++) { UIView *page = (UIView*)[self.pages objectAtIndex:i]; CGRect thisFrame = page.frame; thisFrame.origin.y = self.theScrollView.contentOffset.y+CGRectGetHeight(self.frame)-BOTTOM_OFFSET_HIDE + i * COLLAPSED_OFFSET; page.frame = thisFrame; } [UIView commitAnimations]; } #pragma mark - displaying pages - (void)reloadVisiblePages { NSInteger start = self.visiblePages.location; NSInteger stop = self.visiblePages.location + self.visiblePages.length; for (NSInteger i = start; i < stop; i++) { UIView *page = [self.pages objectAtIndex:i]; if (i == 0 || [self.pages objectAtIndex:i-1] == [NSNull null]) { page.layer.transform = CATransform3DMakeScale(MINIMUM_SCALE, MINIMUM_SCALE, 1.f); } else{ [UIView beginAnimations:@"stackScrolling" context:nil]; [UIView setAnimationDuration:.4f]; page.layer.transform = CATransform3DMakeScale(MINIMUM_SCALE, MINIMUM_SCALE, 1.f); [UIView commitAnimations]; } } } - (void)setPageAtOffset:(CGPoint)offset { if ([self.pages count] > 0 ) { CGPoint start = CGPointMake(offset.x - CGRectGetMinX(self.theScrollView.frame), offset.y -(CGRectGetMinY(self.theScrollView.frame))); CGPoint end = CGPointMake(MAX(0, start.x) + CGRectGetWidth(self.bounds), MAX(OFFSET_TOP, start.y) + CGRectGetHeight(self.bounds)); NSInteger startIndex = 0; for (NSInteger i=0; i < [self.pages count]; i++) { if (PAGE_PEAK * (i+1) > start.y) { startIndex = i; break; } } NSInteger endIndex = 0; for (NSInteger i=0; i < [self.pages count]; i++) { if ((PAGE_PEAK * i < end.y && PAGE_PEAK * (i + 1) >= end.y ) || i == [self.pages count]-1) { endIndex = i + 1; break; } } startIndex = MAX(startIndex - 1, 0); endIndex = MIN(endIndex, [self.pages count] - 1); CGFloat pagedLength = endIndex - startIndex + 1; if (self.visiblePages.location != startIndex || self.visiblePages.length != pagedLength) { _visiblePages.location = startIndex; _visiblePages.length = pagedLength; for (NSInteger i = startIndex; i <= endIndex; i++) { [self setPageAtIndex:i]; } for (NSInteger i = 0; i < startIndex; i ++) { [self removePageAtIndex:i]; } for (NSInteger i = endIndex + 1; i < [self.pages count]; i ++) { [self removePageAtIndex:i]; } } } } - (void)setPageAtIndex:(NSInteger)index { if (index >= 0 && index < [self.pages count]) { UIView *page = [self.pages objectAtIndex:index]; if ((!page || (NSObject*)page == [NSNull null]) && self.delegate) { page = [self.delegate stackView:self pageForIndex:index]; [self.pages replaceObjectAtIndex:index withObject:page]; page.frame = CGRectMake(0.f, index * PAGE_PEAK, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)); if (self.pagesHaveShadows) { [page.layer setShadowOpacity:SHADOW_ALPHA]; [page.layer setShadowOffset:SHADOW_VECTOR]; page.layer.shadowPath = [UIBezierPath bezierPathWithRect:page.bounds].CGPath; page.clipsToBounds = NO; } page.layer.zPosition = index; } if (![page superview]) { if ((index == 0 || [self.pages objectAtIndex:index-1] == [NSNull null]) && index+1 < [self.pages count]) { UIView *topPage = [self.pages objectAtIndex:index+1]; [self.theScrollView insertSubview:page belowSubview:topPage]; } else { [self.theScrollView addSubview:page]; } page.tag = index; } if ([page.gestureRecognizers count] < 2) { UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panned:)]; [page addGestureRecognizer:pan]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]; [page addGestureRecognizer:tap]; } } } #pragma mark - reuse methods - (void)enqueueReusablePage:(UIView*)page { [self.reusablePages addObject:page]; } - (UIView*)dequeueReusablePage { UIView *page = [self.reusablePages lastObject]; if (page && (NSObject*)page != [NSNull null]) { [self.reusablePages removeLastObject]; return page; } return nil; } - (void)removePageAtIndex:(NSInteger)index { UIView *page = [self.pages objectAtIndex:index]; if (page && (NSObject*)page != [NSNull null]) { page.layer.transform = CATransform3DIdentity; [page removeFromSuperview]; [self enqueueReusablePage:page]; [self.pages replaceObjectAtIndex:index withObject:[NSNull null]]; } } #pragma mark - gesture recognizer - (void)tapped:(UIGestureRecognizer*)sender { UIView *page = [sender view]; NSInteger index = [self.pages indexOfObject:page]; CGRect pageTouchFrame = page.frame; if (self.selectedPageIndex == index) { pageTouchFrame.size.height = CGRectGetHeight(pageTouchFrame)-COLLAPSED_OFFSET; } else if (self.selectedPageIndex != -1) { pageTouchFrame.size.height = COLLAPSED_OFFSET; } else if ( index+1 < [self.pages count] ) { pageTouchFrame.size.height = PAGE_PEAK; } [self selectPageAtIndex:index]; [self.delegate stackView:self selectedPageAtIndex:index]; } - (void)panned:(UIPanGestureRecognizer*)recognizer { UIView *page = [recognizer view]; CGPoint translation = [recognizer translationInView:page]; if (recognizer.state == UIGestureRecognizerStateBegan) { self.trackedTranslation = 0; } else if (recognizer.state ==UIGestureRecognizerStateChanged) { CGRect pageFrame = page.frame; pageFrame.origin.y += translation.y; page.frame = pageFrame; self.trackedTranslation += translation.y; [recognizer setTranslation:CGPointMake(0, 0) inView:page]; } else if (recognizer.state == UIGestureRecognizerStateEnded) { if (self.trackedTranslation < -PAGE_PEAK) { NSInteger pageIndex = [self.pages indexOfObject:page]; [self selectPageAtIndex:pageIndex]; [self.delegate stackView:self selectedPageAtIndex:pageIndex]; } else { self.selectedPageIndex = -1; [self resetPages]; } } } #pragma mark - ScrollView Delegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { [self setPageAtOffset:scrollView.contentOffset]; [self reloadVisiblePages]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/StackedPageVC/SSStackedPageView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,704
```objective-c // // YFSlideTitlesViewController.h // BigShow1949 // // Created by zhht01 on 16/3/16. // #import <UIKit/UIKit.h> @interface YFSlideTitlesViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/SlideTitlesView/YFSlideTitlesViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // YFSlideTitlesViewController.m // WSFSlideTitlesView // // Created by WangShengFeng on 3/7/16. // #import "YFSlideTitlesViewController.h" #import "WSFSlideTitlesView.h" @interface YFSlideTitlesViewController () <WSFSlideTitlesViewDelegate> @property (nonatomic, weak) WSFSlideTitlesView *titlesView; @end @implementation YFSlideTitlesViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor lightGrayColor]; // WSFSlideTitlesView [self createWSFSlideTitlesView]; // [self createSelectButton]; } - (void)createWSFSlideTitlesView { // // setting WSFSlideTitlesViewSetting *titlesSetting = [[WSFSlideTitlesViewSetting alloc] init]; titlesSetting.titlesArr = @[ @"", @"", @"", @"", ]; titlesSetting.frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 30); // WSFSlideTitlesView WSFSlideTitlesView *titlesView = [[WSFSlideTitlesView alloc] initWithSetting:titlesSetting]; titlesView.delegate = self; self.titlesView = titlesView; [self.view addSubview:titlesView]; } - (void)createSelectButton { UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeSystem]; [selectButton setTitle:@" 0" forState:UIControlStateNormal]; [selectButton addTarget:self action:@selector(selectButtonClick) forControlEvents:UIControlEventTouchUpInside]; [selectButton sizeToFit]; selectButton.center = CGPointMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.height / 2); [self.view addSubview:selectButton]; } - (void)selectButtonClick { // index [self.titlesView selectButtonAtIndex:0]; } #pragma mark - WSFSlideTitlesViewDelegate - (void)slideTitlesView:(WSFSlideTitlesView *)titlesView didSelectButton:(UIButton *)button atIndex:(NSUInteger)index { // NSLog(@" -%zd- -%@- ", index, [button attributedTitleForState:UIControlStateNormal].string); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/SlideTitlesView/YFSlideTitlesViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
479
```objective-c // // WSFSlideTitlesView.m // WSFSlideTitlesView // // Created by WangShengFeng on 3/7/16. // #import "WSFSlideTitlesView.h" @interface WSFSlideTitlesView () @property (nonatomic, strong) WSFSlideTitlesViewSetting *setting; @property (nonatomic, strong) NSMutableArray *buttonArr; @property (nonatomic, weak) UIButton *selectedButton; @property (nonatomic, weak) UIView *lineView; @end @implementation WSFSlideTitlesView - (NSMutableArray *)buttonArr { if (!_buttonArr) { _buttonArr = [NSMutableArray array]; } return _buttonArr; } + (instancetype)slideTitlesViewWithSetting:(WSFSlideTitlesViewSetting *)setting { return [[self alloc] initWithSetting:setting]; } - (instancetype)initWithSetting:(WSFSlideTitlesViewSetting *)setting { self = [super initWithFrame:setting.frame]; if (self) { _setting = setting; // self.backgroundColor = setting.backgroundColor; // NSUInteger titlesCount = setting.titlesArr.count; CGFloat titlesWidth = setting.frame.size.width / titlesCount; CGFloat titlesHeight = setting.frame.size.height; for (int i = 0; i < titlesCount; ++i) { // type UIButtonTypeCustom UIButton *titlesButton = [UIButton buttonWithType:UIButtonTypeSystem]; [self.buttonArr addObject:titlesButton]; // NSDictionary *attDict = @{ NSFontAttributeName : [UIFont systemFontOfSize:setting.textFontSize], NSForegroundColorAttributeName : setting.textColor, }; NSAttributedString *attStr = [[NSAttributedString alloc] initWithString:setting.titlesArr[i] attributes:attDict]; // NSDictionary *selectedAttDict = @{ NSFontAttributeName : [UIFont systemFontOfSize:setting.textFontSize], NSForegroundColorAttributeName : setting.selectedTextColor, }; NSAttributedString *selectedAttStr = [[NSAttributedString alloc] initWithString:setting.selectedTitlesArr[i] attributes:selectedAttDict]; [titlesButton setAttributedTitle:attStr forState:UIControlStateNormal]; [titlesButton setAttributedTitle:selectedAttStr forState:UIControlStateSelected]; titlesButton.frame = CGRectMake(i * titlesWidth, 0, titlesWidth, titlesHeight); [titlesButton addTarget:self action:@selector(titlesBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:titlesButton]; // if (0 == i) { [self titlesBtnClick:titlesButton]; // if (!setting.lineHidden) { UIView *lineView; if (setting.lineWidth) { lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, setting.lineWidth, setting.lineHeight)]; }else { [titlesButton.titleLabel sizeToFit]; lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, titlesButton.titleLabel.frame.size.width, setting.lineHeight)]; } lineView.backgroundColor = setting.lineColor; lineView.center = CGPointMake((setting.frame.size.width / setting.titlesArr.count) / 2, setting.frame.size.height - setting.lineBottomSpace); self.lineView = lineView; [self addSubview:lineView]; } } } } return self; } - (void)selectButtonAtIndex:(NSUInteger)index { if (index < self.buttonArr.count) { [self titlesBtnClick:self.buttonArr[index]]; } } - (void)titlesBtnClick:(UIButton *)button { { // NSAttributedString *currentStr = [self.selectedButton attributedTitleForState:UIControlStateNormal]; NSAttributedString *toChangeStr = [self.selectedButton attributedTitleForState:UIControlStateSelected]; [self.selectedButton setAttributedTitle:toChangeStr forState:UIControlStateNormal]; [self.selectedButton setAttributedTitle:currentStr forState:UIControlStateSelected]; } { // NSAttributedString *currentStr = [button attributedTitleForState:UIControlStateNormal]; NSAttributedString *toChangeStr = [button attributedTitleForState:UIControlStateSelected]; [button setAttributedTitle:toChangeStr forState:UIControlStateNormal]; [button setAttributedTitle:currentStr forState:UIControlStateSelected]; } // if (!self.setting.lineHidden) { [UIView animateWithDuration:self.setting.animateDuration animations:^{ NSLog(@"lineWidth = %f", self.setting.lineWidth); if (self.setting.lineWidth) { self.lineView.frame = CGRectMake(self.lineView.frame.origin.x, self.lineView.frame.origin.y, self.setting.lineWidth, self.setting.lineHeight); } else { self.lineView.frame = CGRectMake(self.lineView.frame.origin.x, self.lineView.frame.origin.y, button.titleLabel.frame.size.width, self.setting.lineHeight); } self.lineView.center = CGPointMake(button.center.x, self.lineView.center.y); }]; } // self.selectedButton = button; // NSUInteger index = 0; for (int i = 0; i < self.buttonArr.count; ++i) { if ([button isEqual:self.buttonArr[i]]) { index = i; } } if ([self.delegate respondsToSelector:@selector(slideTitlesView:didSelectButton:atIndex:)]) { [self.delegate slideTitlesView:self didSelectButton:button atIndex:index]; } } @end @implementation WSFSlideTitlesViewSetting // - (NSArray *)selectedTitlesArr { if (!_selectedTitlesArr) { _selectedTitlesArr = self.titlesArr; } return _selectedTitlesArr; } - (UIColor *)backgroundColor { if (!_backgroundColor) { _backgroundColor = [UIColor whiteColor]; } return _backgroundColor; } - (UIColor *)textColor { if (!_textColor) { _textColor = [UIColor blackColor]; } return _textColor; } - (UIColor *)selectedTextColor { if (!_selectedTextColor) { _selectedTextColor = [UIColor orangeColor]; } return _selectedTextColor; } - (CGFloat)textFontSize { if (!_textFontSize) { _textFontSize = [UIFont systemFontSize]; } return _textFontSize; } - (CGFloat)selectedTextFontSize { if (!_selectedTextFontSize) { _selectedTextFontSize = self.textFontSize; } return _selectedTextFontSize; } - (BOOL)lineHidden { if (!_lineHidden) { _lineHidden = NO; } return _lineHidden; } - (CGFloat)lineHeight { if (!_lineHeight) { _lineHeight = 1; } return _lineHeight; } - (UIColor *)lineColor { if (!_lineColor) { _lineColor = self.selectedTextColor; } return _lineColor; } - (CGFloat)lineBottomSpace { if (!_lineBottomSpace) { _lineBottomSpace = 1; } return _lineBottomSpace; } - (NSTimeInterval)animateDuration { if (!_animateDuration) { _animateDuration = 0.5; } return _animateDuration; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/SlideTitlesView/WSFSlideTitlesView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,514
```objective-c // // YFWaterflowViewController.h // BigShow1949 // // Created by zhht01 on 16/3/15. // #import <UIKit/UIKit.h> @interface YFWaterflowViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/YFWaterflowViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
52
```objective-c // // YFWaterflowLayout.h // BigShow1949 // // Created by on 15-9-2. // #import <UIKit/UIKit.h> @class YFWaterflowLayout; @protocol YFWaterflowLayoutDelegate <NSObject> - (CGFloat)waterflowLayout:(YFWaterflowLayout *)waterflowLayout heightForItemAtIndexPath:(NSIndexPath *)indexPath itemWidth:(CGFloat)itemWidth; @optional /** * , UIEdgeInsetsMake(10, 10, 10, 10) */ - (UIEdgeInsets)insetsInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout; /** * , 3 */ - (int)maxColumnsInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout; /** * , 10 */ - (CGFloat)rowMarginInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout; /** * , 10 */ - (CGFloat)columnMarginInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout; @end @interface YFWaterflowLayout : UICollectionViewLayout @property (nonatomic, weak) id<YFWaterflowLayoutDelegate> delegate; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/Waterflow/YFWaterflowLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
248
```objective-c // // YFWaterflowViewController.m // BigShow1949 // // Created by on 15-9-2. // #import "YFWaterflowViewController.h" #import "YFShop.h" #import "YFShopCell.h" #import "YFWaterflowLayout.h" #import "MJExtension.h" #import "MJRefresh.h" @interface YFWaterflowViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, YFWaterflowLayoutDelegate> @property (weak, nonatomic) UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *shops; @end @implementation YFWaterflowViewController - (NSMutableArray *)shops { if (!_shops) { self.shops = [[NSMutableArray alloc] init]; } return _shops; } static NSString * const CellId = @"shop"; - (void)viewDidLoad { [super viewDidLoad]; self.title = @""; // [self.shops addObjectsFromArray:[YFShop objectArrayWithFilename:@"1.plist"]]; // YFWaterflowLayout *layout = [[YFWaterflowLayout alloc] init]; layout.delegate = self; // UICollectionView UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; collectionView.dataSource = self; collectionView.delegate = self; collectionView.backgroundColor = [UIColor whiteColor]; [collectionView registerNib:[UINib nibWithNibName:@"YFShopCell" bundle:nil] forCellWithReuseIdentifier:CellId]; [self.view addSubview:collectionView]; self.collectionView = collectionView; // // [self.collectionView addHeaderWithCallback:^{ // NSLog(@""); // }]; // [self.collectionView addFooterWithCallback:^{ // NSLog(@"shang"); // }]; self.collectionView.mj_header = [MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewShops)]; self.collectionView.mj_footer = [MJRefreshFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreShops)]; } - (void)loadNewShops { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSArray *newShops = [YFShop objectArrayWithFilename:@"2.plist"]; [self.shops insertObjects:newShops atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newShops.count)]]; [self.collectionView reloadData]; // stop refresh // [self.collectionView headerEndRefreshing]; [self.collectionView.mj_header endRefreshing]; }); } - (void)loadMoreShops { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSArray *newShops = [YFShop objectArrayWithFilename:@"3.plist"]; [self.shops addObjectsFromArray:newShops]; [self.collectionView reloadData]; // stop refresh [self.collectionView.mj_footer endRefreshing]; }); } #pragma mark - <YFWaterflowLayoutDelegate> - (CGFloat)waterflowLayout:(YFWaterflowLayout *)waterflowLayout heightForItemAtIndexPath:(NSIndexPath *)indexPath itemWidth:(CGFloat)itemWidth { YFShop *shop = self.shops[indexPath.item]; return shop.h * itemWidth / shop.w; } //- (UIEdgeInsets)insetsInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout //{ // return UIEdgeInsetsMake(30, 30, 30, 30); //} //- (int)maxColumnsInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout //{ // return 2; //} //- (CGFloat)rowMarginInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout //{ // return 30; //} // //- (CGFloat)columnMarginInWaterflowLayout:(YFWaterflowLayout *)waterflowLayout //{ // return 50; //} #pragma mark - <UICollectionViewDataSource> - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YFShopCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellId forIndexPath:indexPath]; cell.shop = self.shops[indexPath.item]; return cell; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.shops.count; } #pragma mark - <UICollectionViewDelegate> - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/YFWaterflowViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
950
```objective-c // // YFWaterflowLayout.m // BigShow1949 // // Created by on 15-9-2. // #import "YFWaterflowLayout.h" /** */ static const int YFDefaultMaxColumns = 3; /** */ static const CGFloat YFDefaultRowMargin = 10; /** */ static const CGFloat YFDefaultColumnMargin = 10; /** */ static const UIEdgeInsets YFDefaultInsets = {10, 10, 10, 10}; @interface YFWaterflowLayout() /** Y() */ @property (nonatomic, strong) NSMutableArray *maxYs; @property (nonatomic, strong) NSMutableArray *attrsArray; @end @implementation YFWaterflowLayout - (NSMutableArray *)attrsArray { if (!_attrsArray) { self.attrsArray = [[NSMutableArray alloc] init]; } return _attrsArray; } - (NSMutableArray *)maxYs { if (!_maxYs) { self.maxYs = [[NSMutableArray alloc] init]; } return _maxYs; } - (void)prepareLayout { // y [self.maxYs removeAllObjects]; int maxColumns = self.maxColumns; for (NSUInteger i = 0; i < maxColumns; i++) { [self.maxYs addObject:@(self.insets.top)]; } // cell [self.attrsArray removeAllObjects]; NSUInteger count = [self.collectionView numberOfItemsInSection:0]; for (NSUInteger i = 0; i < count; i++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0]; UICollectionViewLayoutAttributes *attrs = [self layoutAttributesForItemAtIndexPath:indexPath]; [self.attrsArray addObject:attrs]; } } /** * YES, */ - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return YES; } /** * collectionViewContentSize */ - (CGSize)collectionViewContentSize { CGFloat longMaxY = 0; if (self.maxYs.count) { longMaxY = [self.maxYs[0] doubleValue]; // Y for (int i = 1; i < self.maxColumns; i++) { CGFloat maxY = [self.maxYs[i] doubleValue]; if (maxY > longMaxY) { longMaxY = maxY; } } // longMaxY += self.insets.bottom; } return CGSizeMake(0, longMaxY); } /** * indexPathcell */ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { // CGFloat columnMargin = self.columnMargin; // CGFloat rowMargin = self.rowMargin; // CollectionView CGFloat collectionW = self.collectionView.bounds.size.width; int maxColumns = self.maxColumns; UIEdgeInsets insets = self.insets; // item(cell) CGFloat itemW = (collectionW - insets.left - insets.right - (maxColumns - 1) * columnMargin) / maxColumns; // . indexPathitem CGFloat itemH = [self.delegate waterflowLayout:self heightForItemAtIndexPath:indexPath itemWidth:itemW]; // UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; // CGFloat minMaxY = [self.maxYs[0] doubleValue]; // Y int minColumn = 0; // for (int i = 1; i < maxColumns; i++) { CGFloat maxY = [self.maxYs[i] doubleValue]; if (maxY < minMaxY) { minMaxY = maxY; minColumn = i; } } CGFloat itemX = insets.left + minColumn * (itemW + columnMargin); CGFloat itemY = minMaxY + rowMargin; attrs.frame = CGRectMake(itemX, itemY, itemW, itemH); // Y self.maxYs[minColumn] = @(CGRectGetMaxY(attrs.frame)); return attrs; } - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { return self.attrsArray; } #pragma mark - () - (int)maxColumns { if ([self.delegate respondsToSelector:@selector(maxColumnsInWaterflowLayout:)]) { return [self.delegate maxColumnsInWaterflowLayout:self]; } return YFDefaultMaxColumns; } - (CGFloat)rowMargin { if ([self.delegate respondsToSelector:@selector(rowMarginInWaterflowLayout:)]) { return [self.delegate rowMarginInWaterflowLayout:self]; } return YFDefaultRowMargin; } - (CGFloat)columnMargin { if ([self.delegate respondsToSelector:@selector(columnMarginInWaterflowLayout:)]) { return [self.delegate columnMarginInWaterflowLayout:self]; } return YFDefaultColumnMargin; } - (UIEdgeInsets)insets { if ([self.delegate respondsToSelector:@selector(insetsInWaterflowLayout:)]) { return [self.delegate insetsInWaterflowLayout:self]; } return YFDefaultInsets; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/Waterflow/YFWaterflowLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,084
```objective-c // // YFShop.m // BigShow1949 // // Created by on 15-9-2. // #import "YFShop.h" @implementation YFShop @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/Shop/YFShop.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
45
```objective-c // // YFShopCell.m // BigShow1949 // // Created by on 15-9-2. // #import "YFShopCell.h" #import "YFShop.h" #import "UIImageView+WebCache.h" @interface YFShopCell() @property (weak, nonatomic) IBOutlet UIImageView *iconView; @property (weak, nonatomic) IBOutlet UILabel *priceLabel; @end @implementation YFShopCell - (void)setShop:(YFShop *)shop { _shop = shop; self.priceLabel.text = shop.price; [self.iconView sd_setImageWithURL:[NSURL URLWithString:shop.img] placeholderImage:[UIImage imageNamed:@"loading"]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/Shop/YFShopCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
149
```objective-c // // YFShop.h // BigShow1949 // // Created by on 15-9-2. // #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> @interface YFShop : NSObject /** */ @property (nonatomic, assign) CGFloat w; /** */ @property (nonatomic, assign) CGFloat h; /** */ @property (nonatomic, copy) NSString *price; /** url */ @property (nonatomic, copy) NSString *img; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/Shop/YFShop.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
102
```objective-c // // YFShopCell.h // BigShow1949 // // Created by on 15-9-2. // #import <UIKit/UIKit.h> @class YFShop; @interface YFShopCell : UICollectionViewCell @property (nonatomic, strong) YFShop *shop; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/Waterflow/Shop/YFShopCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
65
```objective-c // // YFHomeLabelButton.h // BigShow1949 // // Created by zhht01 on 16/1/22. // #import <UIKit/UIKit.h> @interface YFHomeLabelButton : UIButton /** * * * @param percent */ - (void)adjust:(CGFloat)percent; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/NeteaseHomeVC/YFHomeLabelButton.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
73
```objective-c // // YFHealineViewController.m // BigShow1949 // // Created by zhht01 on 16/1/22. // #import "YFHealineViewController.h" @interface YFHealineViewController () @end @implementation YFHealineViewController - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%@ -- viewDidLoad", self.title); } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 50; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"news"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (cell==nil) { cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } cell.textLabel.text = [NSString stringWithFormat:@"%@ -- ", self.title]; return cell; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/NeteaseHomeVC/YFHealineViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
193
```objective-c // // YFHomeLabelButton.m // BigShow1949 // // Created by zhht01 on 16/1/22. // #import "YFHomeLabelButton.h" static const CGFloat NormalSize = 11.0f; static const CGFloat SelectSize = 20.0f; #define NormalFont [UIFont systemFontOfSize:NormalSize] #define SelectedFont [UIFont systemFontOfSize:SelectSize] static const int NormalRed = 0; static const int NormalGreen = 0; static const int NormalBlue = 0; static const int SelectedRed = 255; static const int SelectedGreen = 0; static const int SelectedBlue = 0; #define Color(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] @interface YFHomeLabelButton() @property (nonatomic, assign) int red; @property (nonatomic, assign) int green; @property (nonatomic, assign) int blue; @end @implementation YFHomeLabelButton - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.red = NormalRed; self.green = NormalGreen; self.blue = NormalBlue; [self setTitleColor:Color(NormalRed, NormalGreen, NormalBlue) forState:UIControlStateNormal]; self.titleLabel.font = NormalFont; } return self; } - (void)setSelected:(BOOL)selected { [super setSelected:selected]; self.titleLabel.font = selected ? SelectedFont : NormalFont; if (selected) { self.red = SelectedRed; self.green = SelectedGreen; self.blue = SelectedBlue; } else { self.red = NormalRed; self.green = NormalGreen; self.blue = NormalBlue; } [self setTitleColor:Color(self.red, self.green, self.blue) forState:UIControlStateSelected]; } - (void)adjust:(CGFloat)percent { // CGFloat size = NormalSize + (SelectSize - NormalSize) * percent; self.titleLabel.font = [UIFont systemFontOfSize:size]; // self.red = NormalRed + (SelectedRed - NormalRed) * percent; self.green = NormalGreen + (SelectedGreen - NormalGreen) * percent; self.blue = NormalBlue + (SelectedBlue - NormalBlue) * percent; [self setTitleColor:Color(self.red, self.green, self.blue) forState:UIControlStateNormal]; [self setTitleColor:Color(self.red, self.green, self.blue) forState:UIControlStateSelected]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/NeteaseHomeVC/YFHomeLabelButton.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
541
```objective-c // // YFNeteaseHomeViewController.h // BigShow1949 // // Created by zhht01 on 16/1/22. // #import <UIKit/UIKit.h> @interface YFNeteaseHomeViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/NeteaseHomeVC/YFNeteaseHomeViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
54
```objective-c // // YFHealineViewController.h // BigShow1949 // // Created by zhht01 on 16/1/22. // #import <UIKit/UIKit.h> @interface YFHealineViewController : UITableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/NeteaseHomeVC/YFHealineViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
54
```objective-c // // YFNeteaseHomeViewController.m // BigShow1949 // // Created by zhht01 on 16/1/22. // #import "YFNeteaseHomeViewController.h" #import "YFHomeLabelButton.h" #import "YFHealineViewController.h" @interface YFNeteaseHomeViewController () <UIScrollViewDelegate> /** */ @property (nonatomic, strong) UIScrollView *labelsScrollView; /** */ @property (nonatomic, strong) UIScrollView *contentsScrollView; @property (nonatomic, weak) YFHomeLabelButton *selectedButton; @end @implementation YFNeteaseHomeViewController #pragma mark - - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; _labelsScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, YFScreen.width, 44)]; _labelsScrollView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_labelsScrollView]; _contentsScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.labelsScrollView.frame), YFScreen.width, YFScreen.height - self.labelsScrollView.frame.size.height)]; _contentsScrollView.backgroundColor = [UIColor greenColor]; [self.view addSubview:_contentsScrollView]; // [self setupChildVcs]; // [self setupLabels]; } /** * */ - (void)setupLabels { // scrollViewcontentInset self.automaticallyAdjustsScrollViewInsets = NO; CGFloat labelButtonW = 90; NSUInteger count = self.childViewControllers.count; for (NSUInteger i = 0; i < count; i++) { // i UIViewController *childVc = self.childViewControllers[i]; // YFHomeLabelButton *labelButton = [[YFHomeLabelButton alloc] init]; labelButton.height = self.labelsScrollView.height; NSLog(@"height = %f", self.labelsScrollView.height); labelButton.width = labelButtonW; labelButton.y = 0; labelButton.x = i * labelButtonW; [labelButton setTitle:childVc.title forState:UIControlStateNormal]; [labelButton addTarget:self action:@selector(labelClick:) forControlEvents:UIControlEventTouchUpInside]; [self.labelsScrollView addSubview:labelButton]; } // self.labelsScrollView.contentSize = CGSizeMake(count * labelButtonW, 0); self.contentsScrollView.contentSize = CGSizeMake(count * [UIScreen mainScreen].bounds.size.width, 0); // self.contentsScrollView.delegate = self; } /** * */ - (void)setupChildVcs { YFHealineViewController *vc0 = [[YFHealineViewController alloc] init]; vc0.title = @""; [self addChildViewController:vc0]; YFHealineViewController *vc1 = [[YFHealineViewController alloc] init]; vc1.title = @""; [self addChildViewController:vc1]; YFHealineViewController *vc2 = [[YFHealineViewController alloc] init]; vc2.title = @""; [self addChildViewController:vc2]; YFHealineViewController *vc3 = [[YFHealineViewController alloc] init]; vc3.title = @""; [self addChildViewController:vc3]; YFHealineViewController *vc4 = [[YFHealineViewController alloc] init]; vc4.title = @""; [self addChildViewController:vc4]; YFHealineViewController *vc5 = [[YFHealineViewController alloc] init]; vc5.title = @""; [self addChildViewController:vc5]; YFHealineViewController *vc6 = [[YFHealineViewController alloc] init]; vc6.title = @""; [self addChildViewController:vc6]; } #pragma mark - /** * */ - (void)labelClick:(YFHomeLabelButton *)labelButton { // self.selectedButton.selected = NO; labelButton.selected = YES; self.selectedButton = labelButton; // NSUInteger index = [self.labelsScrollView.subviews indexOfObject:labelButton]; [self switchChildVc:index]; } /** * * * @param index */ - (void)switchChildVc:(NSUInteger)index { // index UIViewController *newChildVc = self.childViewControllers[index]; if (newChildVc.view.superview == nil) { newChildVc.view.y = 0; newChildVc.view.width = self.contentsScrollView.width; newChildVc.view.height = self.contentsScrollView.height; newChildVc.view.x = index * newChildVc.view.width; [self.contentsScrollView addSubview:newChildVc.view]; } // index [self.contentsScrollView setContentOffset: CGPointMake(newChildVc.view.x, 0) animated:YES]; // CGFloat offsetX = self.selectedButton.centerX - self.labelsScrollView.width * 0.5; CGFloat maxOffsetX = self.labelsScrollView.contentSize.width - self.labelsScrollView.width; if (offsetX < 0) { offsetX = 0; } else if (offsetX > maxOffsetX) { offsetX = maxOffsetX; } CGPoint offset = CGPointMake(offsetX, 0); [self.labelsScrollView setContentOffset:offset animated:YES]; } #pragma mark - <UIScrollViewDelegate> /** * scrollView */ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { NSUInteger index = scrollView.contentOffset.x / scrollView.width; YFHomeLabelButton *labelButton = self.labelsScrollView.subviews[index]; [self labelClick:labelButton]; } /** * scrollView */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat value = scrollView.contentOffset.x / scrollView.width; NSUInteger oneIndex = (NSUInteger)value; NSUInteger twoIndex = oneIndex + 1; CGFloat twoPercent = value - oneIndex; CGFloat onePercent = 1 - twoPercent; YFHomeLabelButton *oneButton = self.labelsScrollView.subviews[oneIndex]; [oneButton adjust:onePercent]; if (twoIndex < self.labelsScrollView.subviews.count) { YFHomeLabelButton *twoButton = self.labelsScrollView.subviews[twoIndex]; [twoButton adjust:twoPercent]; } } //- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate //{ // NSLog(@"scrollViewDidEndDragging"); //} @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/NeteaseHomeVC/YFNeteaseHomeViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,397
```objective-c // // AWCollectionViewDialLayout.h // // // Created by Antoine Wette on 30.10.13. // // info@antoinewette.com // www.antoinewette.com // #import <UIKit/UIKit.h> @interface AWCollectionViewDialLayout : UICollectionViewLayout typedef enum WheelAlignmentType : NSInteger WheelAlignmentType; enum WheelAlignmentType : NSInteger { WHEELALIGNMENTLEFT, WHEELALIGNMENTCENTER }; @property (readwrite, nonatomic, assign) int cellCount; @property (readwrite, nonatomic, assign) int wheelType; @property (readwrite, nonatomic, assign) CGPoint center; @property (readwrite, nonatomic, assign) CGFloat offset; @property (readwrite, nonatomic, assign) CGFloat itemHeight; @property (readwrite, nonatomic, assign) CGFloat xOffset; @property (readwrite, nonatomic, assign) CGSize cellSize; @property (readwrite, nonatomic, assign) CGFloat AngularSpacing; @property (readwrite, nonatomic, assign) CGFloat dialRadius; @property (readonly, nonatomic, strong) NSIndexPath *currentIndexPath; -(id)initWithRadius: (CGFloat) radius andAngularSpacing: (CGFloat) spacing andCellSize: (CGSize) cell andAlignment:(WheelAlignmentType)alignment andItemHeight:(CGFloat)height andXOffset: (CGFloat) xOffset; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HalfCircleViewLayout/AWCollectionViewDialLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
277
```objective-c // // AWCollectionViewDialLayout.m // // // Created by Antoine Wette on 30.10.13. // // info@antoinewette.com // www.antoinewette.com // #import "AWCollectionViewDialLayout.h" @implementation AWCollectionViewDialLayout - (id)init { if ((self = [super init]) != NULL) { [self setup]; } return self; } -(id)initWithRadius: (CGFloat) radius andAngularSpacing: (CGFloat) spacing andCellSize: (CGSize) cell andAlignment:(WheelAlignmentType)alignment andItemHeight:(CGFloat)height andXOffset: (CGFloat) xOff{ if ((self = [super init]) != NULL) { self.dialRadius = radius;//420.0f; self.cellSize = cell;//(CGSize){ 220.0f, 80.0f }; self.itemHeight = height; self.AngularSpacing = spacing;//8.0f; self.xOffset = xOff; self.wheelType = alignment; [self setup]; } return self; } - (void)setup { self.offset = 0.0f; } - (void)prepareLayout { [super prepareLayout]; self.cellCount = (int)[self.collectionView numberOfItemsInSection:0]; self.offset = -self.collectionView.contentOffset.y / self.itemHeight; } - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return YES; } - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSMutableArray *theLayoutAttributes = [[NSMutableArray alloc] init]; float minY = CGRectGetMinY(rect); float maxY = CGRectGetMaxY(rect); int firstIndex = floorf(minY / self.itemHeight); int lastIndex = floorf(maxY / self.itemHeight); int activeIndex = (int)(firstIndex + lastIndex)/2; int maxVisibleOnScreen = 180 / self.AngularSpacing + 2; int firstItem = fmax(0, activeIndex - (int)(maxVisibleOnScreen/2) ); int lastItem = fmin( self.cellCount-1 , activeIndex + (int)(maxVisibleOnScreen/2) ); //float firstItem = fmax(0 , floorf(minY / self.itemHeight) - (90/self.AngularSpacing) ); //float lastItem = fmin( self.cellCount-1 , floorf(maxY / self.itemHeight) ); for( int i = firstItem; i <= lastItem; i++ ){ NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0]; UICollectionViewLayoutAttributes *theAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; [theLayoutAttributes addObject:theAttributes]; } return [theLayoutAttributes copy]; } - (CGSize)collectionViewContentSize { const CGSize theSize = { .width = self.collectionView.bounds.size.width, .height = (self.cellCount-1) * self.itemHeight + self.collectionView.bounds.size.height, }; return(theSize); } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { double newIndex = (indexPath.item + self.offset); UICollectionViewLayoutAttributes *theAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; theAttributes.size = self.cellSize; float scaleFactor; float deltaX; CGAffineTransform translationT; CGAffineTransform rotationT = CGAffineTransformMakeRotation(self.AngularSpacing* newIndex *M_PI/180); if(indexPath.item == 3){ NSLog(@"angle 3 :%f", self.AngularSpacing* newIndex); } if( self.wheelType == WHEELALIGNMENTLEFT){ scaleFactor = fmax(0.6, 1 - fabs( newIndex *0.25)); deltaX = self.cellSize.width/2; theAttributes.center = CGPointMake(-self.dialRadius + self.xOffset , self.collectionView.bounds.size.height/2 + self.collectionView.contentOffset.y); translationT =CGAffineTransformMakeTranslation(self.dialRadius + (deltaX*scaleFactor) , 0); }else { scaleFactor = fmax(0.4, 1 - fabs( newIndex *0.50)); deltaX = self.collectionView.bounds.size.width/2; theAttributes.center = CGPointMake(-self.dialRadius + self.xOffset , self.collectionView.bounds.size.height/2 + self.collectionView.contentOffset.y); translationT =CGAffineTransformMakeTranslation(self.dialRadius + ((1 - scaleFactor) * -30) , 0); } CGAffineTransform scaleT = CGAffineTransformMakeScale(scaleFactor, scaleFactor); theAttributes.alpha = scaleFactor; /* if( fabs(self.AngularSpacing* newIndex) > 90 ){ theAttributes.hidden = YES; }else{ theAttributes.hidden = NO; } */ theAttributes.transform = CGAffineTransformConcat(scaleT, CGAffineTransformConcat(translationT, rotationT)); theAttributes.zIndex = indexPath.item; return(theAttributes); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HalfCircleViewLayout/AWCollectionViewDialLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,093
```objective-c // // YFHalfCircleLayoutViewController.m // BigShow1949 // // Created by zhht01 on 16/3/16. // #import "YFHalfCircleLayoutViewController.h" #import "AWCollectionViewDialLayout.h" @interface YFHalfCircleLayoutViewController () @property (nonatomic, strong) UIBarButtonItem *editBtnItem; @end static NSString *cellId = @"cellId"; static NSString *cellId2 = @"cellId2"; @implementation YFHalfCircleLayoutViewController{ NSMutableDictionary *thumbnailCache; BOOL showingSettings; UIView *settingsView; UILabel *radiusLabel; UISlider *radiusSlider; UILabel *angularSpacingLabel; UISlider *angularSpacingSlider; UILabel *xOffsetLabel; UISlider *xOffsetSlider; UISegmentedControl *exampleSwitch; AWCollectionViewDialLayout *dialLayout; int type; } @synthesize collectionView, items; - (void)viewDidLoad { [super viewDidLoad]; type = 0; showingSettings = NO; [collectionView registerNib:[UINib nibWithNibName:@"dialCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:cellId]; [collectionView registerNib:[UINib nibWithNibName:@"dialCell2" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:cellId2]; NSError *error; NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"players" ofType:@"json"]; NSLog(@"jsonPath = %@", jsonPath); NSString *jsonString = [[NSString alloc] initWithContentsOfFile:jsonPath encoding:NSUTF8StringEncoding error:NULL]; NSLog(@"jsonString:%@",jsonString); items = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error]; settingsView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-44)]; [settingsView setBackgroundColor:[UIColor colorWithWhite:1.0 alpha:0.6]]; [self.view addSubview:settingsView]; [self buildSettings]; CGFloat radius = radiusSlider.value * 1000; CGFloat angularSpacing = angularSpacingSlider.value * 90; CGFloat xOffset = xOffsetSlider.value * 320; CGFloat cell_width = 240; CGFloat cell_height = 100; [radiusLabel setText:[NSString stringWithFormat:@"Radius: %i", (int)radius]]; [angularSpacingLabel setText:[NSString stringWithFormat:@"Angular spacing: %i", (int)angularSpacing]]; [xOffsetLabel setText:[NSString stringWithFormat:@"X offset: %i", (int)xOffset]]; dialLayout = [[AWCollectionViewDialLayout alloc] initWithRadius:radius andAngularSpacing:angularSpacing andCellSize:CGSizeMake(cell_width, cell_height) andAlignment:WHEELALIGNMENTCENTER andItemHeight:cell_height andXOffset:xOffset]; [collectionView setCollectionViewLayout:dialLayout]; UIBarButtonItem *editBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"edit" style:UIBarButtonItemStylePlain target:self action:@selector(toggleSettingsView)]; self.navigationItem.rightBarButtonItem = editBtnItem; self.editBtnItem = editBtnItem; [self switchExample]; } -(void)buildSettings{ NSArray *viewArr = [[NSBundle mainBundle] loadNibNamed:@"iphone_settings_view" owner:self options:nil]; UIView *innerView = [viewArr objectAtIndex:0]; CGRect frame = innerView.frame; frame.origin.y = (self.view.frame.size.height/2 - frame.size.height/2)/2; innerView.frame = frame; [settingsView addSubview:innerView]; radiusLabel = (UILabel*)[innerView viewWithTag:100]; radiusSlider = (UISlider*)[innerView viewWithTag:200]; [radiusSlider addTarget:self action:@selector(updateDialSettings) forControlEvents:UIControlEventValueChanged]; angularSpacingLabel = (UILabel*)[innerView viewWithTag:101]; angularSpacingSlider = (UISlider*)[innerView viewWithTag:201]; [angularSpacingSlider addTarget:self action:@selector(updateDialSettings) forControlEvents:UIControlEventValueChanged]; xOffsetLabel = (UILabel*)[innerView viewWithTag:102]; xOffsetSlider = (UISlider*)[innerView viewWithTag:202]; [xOffsetSlider addTarget:self action:@selector(updateDialSettings) forControlEvents:UIControlEventValueChanged]; exampleSwitch = (UISegmentedControl*)[innerView viewWithTag:203]; [exampleSwitch addTarget:self action:@selector(switchExample) forControlEvents:UIControlEventValueChanged]; } -(void)switchExample{ type = (int)exampleSwitch.selectedSegmentIndex; CGFloat radius = 0 ,angularSpacing = 0, xOffset = 0; if(type == 0){ [dialLayout setCellSize:CGSizeMake(240, 100)]; [dialLayout setWheelType:WHEELALIGNMENTLEFT]; radius = 300; angularSpacing = 18; xOffset = 70; }else if(type == 1){ [dialLayout setCellSize:CGSizeMake(260, 50)]; [dialLayout setWheelType:WHEELALIGNMENTCENTER]; radius = 320; angularSpacing = 5; xOffset = 124; } [radiusLabel setText:[NSString stringWithFormat:@"Radius: %i", (int)radius]]; radiusSlider.value = radius/1000; [dialLayout setDialRadius:radius]; [angularSpacingLabel setText:[NSString stringWithFormat:@"Angular spacing: %i", (int)angularSpacing]]; angularSpacingSlider.value = angularSpacing / 90; [dialLayout setAngularSpacing:angularSpacing]; [xOffsetLabel setText:[NSString stringWithFormat:@"X offset: %i", (int)xOffset]]; xOffsetSlider.value = xOffset/320; [dialLayout setXOffset:xOffset]; [collectionView reloadData]; } -(void)updateDialSettings{ CGFloat radius = radiusSlider.value * 1000; CGFloat angularSpacing = angularSpacingSlider.value * 90; CGFloat xOffset = xOffsetSlider.value * 320; [radiusLabel setText:[NSString stringWithFormat:@"Radius: %i", (int)radius]]; [dialLayout setDialRadius:radius]; [angularSpacingLabel setText:[NSString stringWithFormat:@"Angular spacing: %i", (int)angularSpacing]]; [dialLayout setAngularSpacing:angularSpacing]; [xOffsetLabel setText:[NSString stringWithFormat:@"X offset: %i", (int)xOffset]]; [dialLayout setXOffset:xOffset]; [dialLayout invalidateLayout]; //[collectionView reloadData]; NSLog(@"updateDialSettings"); } -(void)toggleSettingsView{ CGRect frame = settingsView.frame; if(showingSettings){ self.editBtnItem.title = @"Edit"; frame.origin.y = self.view.frame.size.height; }else{ self.editBtnItem.title = @"Close"; frame.origin.y = 44; } [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ settingsView.frame = frame; } completion:^(BOOL finished) { }]; showingSettings = !showingSettings; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.items.count; } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } //-(BOOL)prefersStatusBarHidden{ // return YES; //} -(UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath{ UICollectionViewCell *cell; if(type == 0){ cell = [cv dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; }else{ cell = [cv dequeueReusableCellWithReuseIdentifier:cellId2 forIndexPath:indexPath]; } NSDictionary *item = [self.items objectAtIndex:indexPath.item]; NSString *playerName = [item valueForKey:@"name"]; UILabel *nameLabel = (UILabel*)[cell viewWithTag:101]; [nameLabel setText:playerName]; NSString *hexColor = [item valueForKey:@"team-color"]; if(type == 0){ UIView *borderView = [cell viewWithTag:102]; borderView.layer.borderWidth = 1; borderView.layer.borderColor = [self colorFromHex:hexColor].CGColor; NSString *imgURL = [item valueForKey:@"picture"]; UIImageView *imgView = (UIImageView*)[cell viewWithTag:100]; [imgView setImage:nil]; __block UIImage *imageProduct = [thumbnailCache objectForKey:imgURL]; if(imageProduct){ imgView.image = imageProduct; } else{ dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(queue, ^{ UIImage *image = [UIImage imageNamed:imgURL]; dispatch_async(dispatch_get_main_queue(), ^{ imgView.image = image; [thumbnailCache setValue:image forKey:imgURL]; }); }); } }else{ nameLabel.textColor = [self colorFromHex:hexColor]; } return cell; } -(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"didEndDisplayingCell:%i", (int)indexPath.item); } #pragma mark - UICollectionViewDelegate methods - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(240, 100); } - (UIEdgeInsets)collectionView: (UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0 , 0, 0, 0); } - (unsigned int)intFromHexString:(NSString *)hexStr { unsigned int hexInt = 0; // Create scanner NSScanner *scanner = [NSScanner scannerWithString:hexStr]; // Tell scanner to skip the # character [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]]; // Scan hex value [scanner scanHexInt:&hexInt]; return hexInt; } -(UIColor*)colorFromHex:(NSString*)hexString{ unsigned int hexint = [self intFromHexString:hexString]; // Create color object, specifying alpha as well UIColor *color = [UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255 green:((CGFloat) ((hexint & 0xFF00) >> 8))/255 blue:((CGFloat) (hexint & 0xFF))/255 alpha:1]; return color; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HalfCircleViewLayout/YFHalfCircleLayoutViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,314
```objective-c // // YFHalfCircleLayoutViewController.h // BigShow1949 // // Created by zhht01 on 16/3/16. // #import <UIKit/UIKit.h> @interface YFHalfCircleLayoutViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate> @property (nonatomic, weak) IBOutlet UICollectionView *collectionView; //@property (nonatomic, weak) IBOutlet UIBarButtonItem *editBtn; @property NSArray *items; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HalfCircleViewLayout/YFHalfCircleLayoutViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
89
```objective-c // // YFHorizontalScroll.m // BigShow1949 // // Created by zhht01 on 16/5/9. // #import "YFHorizontalScrollViewController.h" #import "HWCollectionViewCell.h" #import "HWLineLayout.h" #import "HWCircleLayout.h" @interface YFHorizontalScrollViewController () <UICollectionViewDataSource, UICollectionViewDelegate> @property (weak, nonatomic) UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *data; @end @implementation YFHorizontalScrollViewController /* 1.cell nib registerNib: dequeue cell -(void)awakeFromNib nib registerClass: , dequeue cell - (id)initWithStyle:withReuseableCellIdentifier: 2. dequeueReuseableCellWithIdentifier:cellcell dequeueReuseableCellWithIdentifier:forIndexPath:cell */ - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor lightGrayColor]; // == cell\cell HWLineLayout *layout = [[HWLineLayout alloc] init]; // HWCircleLayout *layout = [[HWCircleLayout alloc] init]; // UICollectionView UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, YFScreen.width, 200) collectionViewLayout:layout]; collectionView.dataSource = self; collectionView.delegate = self; [collectionView registerNib:[UINib nibWithNibName:@"HWCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"]; [self.view addSubview:collectionView]; self.collectionView = collectionView; } #pragma mark - <UICollectionViewDataSource> - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { HWCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; cell.index = self.data[indexPath.item]; return cell; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.data.count; } #pragma mark - <UICollectionViewDelegate> - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { // [self.data removeObjectAtIndex:indexPath.item]; // [collectionView deleteItemsAtIndexPaths:@[indexPath]]; } //BOOL isCircle = YES; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if ([self.collectionView.collectionViewLayout isKindOfClass:[HWLineLayout class]]) { [self.collectionView setCollectionViewLayout:[[HWCircleLayout alloc] init] animated:YES]; } else { [self.collectionView setCollectionViewLayout:[[HWLineLayout alloc] init] animated:YES]; } } - (NSMutableArray *)data { if (!_data) { self.data = [[NSMutableArray alloc] init]; for (NSUInteger i = 0; i < 20; i++) { [self.data addObject:[NSString stringWithFormat:@"%zd", i]]; } } return _data; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/YFHorizontalScrollViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
605
```objective-c // // HWCircleLayout.m // CollectionView // // Created by apple on 14/12/27. // #import "HWCircleLayout.h" @implementation HWCircleLayout /** * UICollectionView(cell\SupplementaryView\DecorationView) * * @return UICollectionViewLayoutAttributes, cellUICollectionViewLayoutAttributes */ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSMutableArray *array = [NSMutableArray array]; NSUInteger count = [self.collectionView numberOfItemsInSection:0]; for (NSUInteger i = 0; i < count; i++) { NSIndexPath *path = [NSIndexPath indexPathForItem:i inSection:0]; UICollectionViewLayoutAttributes *attrs = [self layoutAttributesForItemAtIndexPath:path]; [array addObject:attrs]; } return array; } // CollectionViewtableView // tableView : cell\header\footer\section footer\section header // CollectionView : cell\SupplementaryView\DecorationView /** * indexPathcell */ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat itemWH = 40; CGFloat collectionViewW = self.collectionView.bounds.size.width; CGFloat collectionViewH = self.collectionView.bounds.size.height; // CGPoint circleCenter = CGPointMake(collectionViewW * 0.5, collectionViewH * 0.5); // CGFloat circleRadius = (MIN(collectionViewH, collectionViewW) - itemWH) * 0.5; NSUInteger count = [self.collectionView numberOfItemsInSection:0]; UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; // cell attrs.size = CGSizeMake(itemWH, itemWH); // cell if (count == 1) { attrs.center = circleCenter; } else { CGFloat angleUnit = M_PI * 2 / count; // CGFloat angle = indexPath.item * angleUnit; // item CGFloat attrsCenterX = circleCenter.x + circleRadius * cos(angle); CGFloat attrsCenterY = circleCenter.y + circleRadius * sin(angle); attrs.center = CGPointMake(attrsCenterX, attrsCenterY); // zIndexcell // attrs.zIndex = count - indexPath.item; } return attrs; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/HWCircleLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
484
```objective-c // // YFHorizontalScroll.h // BigShow1949 // // Created by zhht01 on 16/5/9. // #import <UIKit/UIKit.h> @interface YFHorizontalScrollViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/YFHorizontalScrollViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // HWCollectionViewCell.h // CollectionView // // Created by apple on 14/12/25. // #import <UIKit/UIKit.h> @interface HWCollectionViewCell : UICollectionViewCell @property (nonatomic, copy) NSString *index; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/HWCollectionViewCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
54
```objective-c // // HWCollectionViewCell.m // CollectionView // // Created by apple on 14/12/25. // #import "HWCollectionViewCell.h" @interface HWCollectionViewCell() @property (weak, nonatomic) IBOutlet UILabel *label; @end @implementation HWCollectionViewCell - (void)awakeFromNib { // Initialization code self.layer.borderWidth = 5; self.layer.borderColor = [UIColor whiteColor].CGColor; self.layer.cornerRadius = 5; } - (void)setIndex:(NSString *)index { _index = [index copy]; self.label.text = index; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/HWCollectionViewCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
129
```objective-c // // HWCircleLayout.h // CollectionView // // Created by apple on 14/12/27. // #import <UIKit/UIKit.h> @interface HWCircleLayout : UICollectionViewLayout @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/HWCircleLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
45
```objective-c // // HWLineLayout.h // CollectionView // // Created by apple on 14/12/25. // #import <UIKit/UIKit.h> @interface HWLineLayout : UICollectionViewFlowLayout @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/HWLineLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
45
```objective-c // // HWLineLayout.m // CollectionView // // Created by apple on 14/12/25. // #import "HWLineLayout.h" @implementation HWLineLayout - (instancetype)init { if (self = [super init]) { self.itemSize = CGSizeMake(100, 100); self.minimumLineSpacing = 50; // item self.minimumInteritemSpacing = 50; // cell // self.scrollDirection = UICollectionViewScrollDirectionHorizontal; } return self; } /* YESscroll */ - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return YES; } /** * , */ - (void)prepareLayout { // NSLog(@"collectionView.bounds = %@", NSStringFromCGRect(self.collectionView.bounds)); // NSLog(@"itemSize = %@", NSStringFromCGSize(self.itemSize)); CGFloat inset = (self.collectionView.bounds.size.width - self.itemSize.width) * 0.5; self.sectionInset = UIEdgeInsetsMake(0, inset, 0, inset); // self.sectionInsetself.collectionView.contentInsets // self.sectionInsetcollectionViewcontentInsets } /** * collectionView * * @param proposedContentOffset ,collectionViewcontentOffset * @param velocity * * @return collectionViewcontentOffset */ - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity { // x CGFloat screenCenterX = proposedContentOffset.x + self.collectionView.bounds.size.width * 0.5; // CGRect visiableRect; visiableRect.origin = proposedContentOffset; visiableRect.size = self.collectionView.bounds.size; // cell NSArray *array = [super layoutAttributesForElementsInRect:visiableRect]; CGFloat minDelta = MAXFLOAT; for (UICollectionViewLayoutAttributes *attrs in array) { // cell NSLog(@"attrs.center.x = %f, screenCenterX = %f, attrs.center.x - screenCenterX = %f", attrs.center.x, screenCenterX, attrs.center.x - screenCenterX); if (ABS(attrs.center.x - screenCenterX) < ABS(minDelta)) { minDelta = attrs.center.x - screenCenterX; NSLog(@"minDelta =%f", minDelta); }else { NSLog(@""); } } return CGPointMake(proposedContentOffset.x + minDelta, proposedContentOffset.y); } /* UICollectionViewLayoutAttributes: cell\\ */ /** * UICollectionView * * @return UICollectionViewLayoutAttributes, cellUICollectionViewLayoutAttributes */ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSArray *array = [super layoutAttributesForElementsInRect:rect]; // x CGFloat screenCenterX = self.collectionView.contentOffset.x + self.collectionView.bounds.size.width * 0.5; // // CGRect visiableRect; // visiableRect.size = self.collectionView.bounds.size; // visiableRect.origin = self.collectionView.contentOffset; for (UICollectionViewLayoutAttributes *attrs in array) { CGFloat scale = 1.0 + 0.5 * (1.0 - (ABS(screenCenterX - attrs.center.x) / 200)); NSLog(@"screenCenterX = %f, attrs.center.x = %f, abs= %f, scale = %f", screenCenterX, attrs.center.x, screenCenterX - attrs.center.x, scale); attrs.transform = CGAffineTransformMakeScale(scale, scale); // attrs.transform3D = CATransform3DMakeScale(scale, scale, 1.0); // CGFloat distance = ABS(screenCenterX - attrs.center.x); // attrs.transform3D = CATransform3DMakeRotation(M_PI_2 * (distance / 200), 0, 1, 0); } NSLog(@"######################"); return array; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/HorizontalScroll/HWLineLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
837
```objective-c // // RGCardLayoutViewController.h // BigShow1949 // // Created by zhht01 on 16/3/15. // #import <UIKit/UIKit.h> @interface RGCardLayoutViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/RGCardViewLayout/RGCardLayoutViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // RGCardViewLayout.h // RGCardViewLayout // // Created by ROBERA GELETA on 1/23/15. // #import <UIKit/UIKit.h> @interface RGCardViewLayout : UICollectionViewFlowLayout @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/RGCardViewLayout/RGCardViewLayout.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
75
```objective-c // // RGCardLayoutViewController.m // BigShow1949 // // Created by zhht01 on 16/3/15. // #define TAG 99 #import "RGCardLayoutViewController.h" #import "RGCollectionViewCell.h" @interface RGCardLayoutViewController () @end @implementation RGCardLayoutViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 1; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 4; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { RGCollectionViewCell *cell = (RGCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath]; [self configureCell:cell withIndexPath:indexPath]; return cell; } - (void)configureCell:(RGCollectionViewCell *)cell withIndexPath:(NSIndexPath *)indexPath { UIView *subview = [cell.contentView viewWithTag:TAG]; [subview removeFromSuperview]; switch (indexPath.section) { case 0: cell.imageView.image = [UIImage imageNamed:@"i1.jpg"]; cell.mainLabel.text = @"Glaciers"; break; case 1: cell.imageView.image = [UIImage imageNamed:@"i2.jpg"]; cell.mainLabel.text = @"Parrots"; break; case 2: cell.imageView.image = [UIImage imageNamed:@"i3.jpg"]; cell.mainLabel.text = @"Whales"; break; case 3: cell.imageView.image = [UIImage imageNamed:@"i4.jpg"]; cell.mainLabel.text = @"Lake View"; break; case 4: cell.imageView.image = [UIImage imageNamed:@"i5.jpg"]; break; default: break; } } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/RGCardViewLayout/RGCardLayoutViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
407
```objective-c // // RGCollectionViewCell.h // RGCardViewLayout // // Created by ROBERA GELETA on 1/23/15. // #import <UIKit/UIKit.h> @interface RGCollectionViewCell : UICollectionViewCell @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (weak, nonatomic) IBOutlet UILabel *mainLabel; @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/RGCardViewLayout/RGCollectionViewCell.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
95
```objective-c // // RGCardViewLayout.m // RGCardViewLayout // // Created by ROBERA GELETA on 1/23/15. // #import "RGCardViewLayout.h" @implementation RGCardViewLayout { CGFloat previousOffset; NSIndexPath *mainIndexPath; NSIndexPath *movingInIndexPath; CGFloat diffrence; } - (void)prepareLayout { [super prepareLayout]; [self setupLayout]; } - (void)setupLayout { CGFloat inset = self.collectionView.bounds.size.width * (6/64.0f); inset = floor(inset); NSLog(@"bound = %@", NSStringFromCGRect(self.collectionView.bounds)); self.itemSize = CGSizeMake(self.collectionView.bounds.size.width - (2 *inset), self.collectionView.bounds.size.height * 3/4); self.sectionInset = UIEdgeInsetsMake(0,inset, 0,inset); self.scrollDirection = UICollectionViewScrollDirectionHorizontal; } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath]; [self applyTransformToLayoutAttributes:attributes]; return attributes; } // indicate that we want to redraw as we scroll - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return YES; } -(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSArray *attributes = [super layoutAttributesForElementsInRect:rect]; NSArray *cellIndices = [self.collectionView indexPathsForVisibleItems]; if(cellIndices.count == 0 ) { return attributes; } else if (cellIndices.count == 1) { mainIndexPath = cellIndices.firstObject; movingInIndexPath = nil; }else if(cellIndices.count > 1) { NSIndexPath *firstIndexPath = cellIndices.firstObject; if(firstIndexPath == mainIndexPath) { movingInIndexPath = cellIndices[1]; } else { movingInIndexPath = cellIndices.firstObject; mainIndexPath = cellIndices[1]; } } diffrence = self.collectionView.contentOffset.x - previousOffset; previousOffset = self.collectionView.contentOffset.x; for (UICollectionViewLayoutAttributes *attribute in attributes) { [self applyTransformToLayoutAttributes:attribute]; } return attributes; } - (void)applyTransformToLayoutAttributes:(UICollectionViewLayoutAttributes *)attribute { if(attribute.indexPath.section == mainIndexPath.section) { UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:mainIndexPath]; attribute.transform3D = [self transformFromView:cell]; } else if (attribute.indexPath.section == movingInIndexPath.section) { UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:movingInIndexPath]; attribute.transform3D = [self transformFromView:cell]; } } - (CGRect)newFrameFromOriginal:(CGRect)orginalFrame withView:(UIView *)view { CGFloat computedY = [self heightOffsetForView:view]; return orginalFrame; } #pragma mark - Logica - (CGFloat)baseOffsetForView:(UIView *)view { UICollectionViewCell *cell = (UICollectionViewCell *)view; CGFloat offset = ([self.collectionView indexPathForCell:cell].section) * self.collectionView.bounds.size.width; return offset; } - (CGFloat)heightOffsetForView:(UIView *)view { CGFloat height; CGFloat baseOffsetForCurrentView = [self baseOffsetForView:view ]; CGFloat currentOffset = self.collectionView.contentOffset.x; CGFloat scrollViewWidth = self.collectionView.bounds.size.width; //TODO:make this constant a certain proportion of the collection view height = 120 * (currentOffset - baseOffsetForCurrentView)/scrollViewWidth; if(height < 0 ) { height = - 1 *height; } return height; } - (CGFloat)angleForView:(UIView *)view { CGFloat baseOffsetForCurrentView = [self baseOffsetForView:view ]; CGFloat currentOffset = self.collectionView.contentOffset.x; CGFloat scrollViewWidth = self.collectionView.bounds.size.width; CGFloat angle = (currentOffset - baseOffsetForCurrentView)/scrollViewWidth; return angle; } - (BOOL)xAxisForView:(UIView *)view { CGFloat baseOffsetForCurrentView = [self baseOffsetForView:view ]; CGFloat currentOffset = self.collectionView.contentOffset.x; CGFloat offset = (currentOffset - baseOffsetForCurrentView); if(offset >= 0) { return YES; } return NO; } #pragma mark - Transform Related Calculation - (CATransform3D)transformFromView:(UIView *)view { CGFloat angle = [self angleForView:view]; CGFloat height = [self heightOffsetForView:view]; BOOL xAxis = [self xAxisForView:view]; return [self transformfromAngle:angle height:height xAxis:xAxis]; } - (CATransform3D)transformfromAngle:(CGFloat )angle height:(CGFloat) height xAxis:(BOOL)axis { CATransform3D t = CATransform3DIdentity; t.m34 = 1.0/-500; if (axis) { t = CATransform3DRotate(t,angle, 1, 1, 0); } else { t = CATransform3DRotate(t,angle, -1, 1, 0); } // t = CATransform3DTranslate(t, 0, height, 0); return t; } @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/RGCardViewLayout/RGCardViewLayout.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,224
```objective-c // // RGCollectionViewCell.m // RGCardViewLayout // // Created by ROBERA GELETA on 1/23/15. // #import "RGCollectionViewCell.h" @implementation RGCollectionViewCell @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/RGCardViewLayout/RGCollectionViewCell.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
71
```objective-c // // ArtDefaultViewController.h // Demo // // Created by weijingyun on 16/10/21. // #import <UIKit/UIKit.h> @interface ArtWholePullViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtWholePullViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // ArtDefaultViewController.m // Demo // // Created by weijingyun on 16/10/21. // #import "ArtDefaultViewController.h" #import "JYPagingView.h" #import "ArtTableViewController.h" @interface ArtDefaultViewController ()<HHHorizontalPagingViewDelegate> @property (nonatomic, strong) HHHorizontalPagingView *pagingView; @property (nonatomic, strong) NSLayoutConstraint *topConstraint; @end @implementation ArtDefaultViewController - (void)viewDidLoad { [super viewDidLoad]; // self.edgesForExtendedLayout = UIRectEdgeNone; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; [self.pagingView reload]; } - (void)viewWillAppear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:YES animated:animated]; [super viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:NO animated:animated]; [super viewWillDisappear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)showText:(NSString *)str{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate: self cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [alert dismissWithClickedButtonIndex:0 animated:YES]; }); } #pragma mark - HHHorizontalPagingViewDelegate // UIScrollView - (NSInteger)numberOfSectionsInPagingView:(HHHorizontalPagingView *)pagingView{ return 5; } - (UIScrollView *)pagingView:(HHHorizontalPagingView *)pagingView viewAtIndex:(NSInteger)index{ ArtTableViewController *vc = [[ArtTableViewController alloc] init]; [self addChildViewController:vc]; vc.index = index; vc.fillHight = self.pagingView.segmentTopSpace + 36; return (UIScrollView *)vc.view; } //headerView - (CGFloat)headerHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 250; } - (UIView *)headerViewInPagingView:(HHHorizontalPagingView *)pagingView{ __weak typeof(self)weakSelf = self; UIView *headerView = [[UIView alloc] init]; UIImage *image = [UIImage imageNamed:@"headerImage"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.clipsToBounds = YES; [headerView addSubview:imageView]; imageView.translatesAutoresizingMaskIntoConstraints = NO; self.topConstraint = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeTop multiplier:1 constant:0]; [headerView addConstraint:self.topConstraint]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeRight multiplier:1 constant:0]]; headerView.backgroundColor = [UIColor orangeColor]; [headerView whenTapped:^{ [weakSelf showText:@"headerView click"]; }]; UIView *view = [[UIView alloc] init]; [headerView addSubview:view]; view.backgroundColor = [UIColor redColor]; view.frame = CGRectMake(0, 0, 100, 200); view.tag = 1000; [view whenTapped:^{ [weakSelf showText:@"redView click"]; }]; UIView *view1 = [[UIView alloc] init]; [view addSubview:view1]; view1.tag = 1001; view1.backgroundColor = [UIColor grayColor]; view1.frame = CGRectMake(50, 50, 50, 100); [view1 whenTapped:^{ [weakSelf showText:@"grayView click"]; }]; self.topConstraint.constant = - self.pagingView.pullOffset; return headerView; } //segmentButtons - (CGFloat)segmentHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 36.; } - (NSArray<UIButton*> *)segmentButtonsInPagingView:(HHHorizontalPagingView *)pagingView{ NSMutableArray *buttonArray = [NSMutableArray array]; for(int i = 0; i < 6; i++) { UIButton *segmentButton = [UIButton buttonWithType:UIButtonTypeCustom]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line"] forState:UIControlStateNormal]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line_select"] forState:UIControlStateSelected]; NSString *str = i == 5 ? @"" : [NSString stringWithFormat:@"view%@",@(i)]; [segmentButton setTitle:str forState:UIControlStateNormal]; [segmentButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; segmentButton.adjustsImageWhenHighlighted = NO; [buttonArray addObject:segmentButton]; } return [buttonArray copy]; } // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelected:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); if (selectedIndex == 5) { [self.navigationController popViewControllerAnimated:YES]; } } - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelectedSameItem:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); } // - (void)pagingView:(HHHorizontalPagingView*)pagingView didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex{ NSLog(@"%s \n %tu to %tu",__func__,aIndex,toIndex); } /* magnifyTopConstraint magnifyTopConstraint */ - (void)pagingView:(HHHorizontalPagingView*)pagingView scrollTopOffset:(CGFloat)offset{ // NSLog(@"%f",offset); if (offset > 0) { return; } self.topConstraint.constant = offset; } #pragma mark - - (HHHorizontalPagingView *)pagingView{ if (!_pagingView) { CGSize size = [UIScreen mainScreen].bounds.size; _pagingView = [[HHHorizontalPagingView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height) delegate:self]; _pagingView.segmentTopSpace = 20; _pagingView.isGesturesSimulate = YES; _pagingView.segmentView.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; // _pagingView.maxCacheCout = 5.; [self.view addSubview:_pagingView]; } return _pagingView; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtDefaultViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,520
```objective-c // // ArtDefaultViewController.h // Demo // // Created by weijingyun on 16/10/21. // #import <UIKit/UIKit.h> @interface ArtScrollHeaderViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtScrollHeaderViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
46
```objective-c // // ArtDefaultViewController.h // Demo // // Created by weijingyun on 16/10/21. // #import <UIKit/UIKit.h> @interface ArtDefaultViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtDefaultViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
45
```objective-c // // ArtTableViewController.m // Demo // // Created by weijingyun on 16/5/28. // #import "ArtTableViewController.h" #import "SVPullToRefresh.h" #import "JYPagingView.h" @interface ArtTableViewController()<UITableViewDelegate,UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @end @implementation ArtTableViewController - (void)loadView{ self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; self.view = self.tableView; } - (void)viewDidLoad{ [super viewDidLoad]; if (!self.allowPullToRefresh) { return; } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takeBack:) name:kHHHorizontalTakeBackRefreshEndNotification object:self.tableView]; __weak typeof(self)weakSelf = self; [self.tableView addPullToRefreshOffset:self.pullOffset withActionHandler:^{ [[NSNotificationCenter defaultCenter] postNotificationName:kHHHorizontalScrollViewRefreshStartNotification object:weakSelf.tableView userInfo:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView.pullToRefreshView stopAnimating]; [[NSNotificationCenter defaultCenter] postNotificationName:kHHHorizontalScrollViewRefreshEndNotification object:weakSelf.tableView userInfo:nil]; }); }]; } - (void)takeBack:(NSNotification *)noti{ [self.tableView.pullToRefreshView stopAnimating:NO]; } - (void)dealloc{ NSLog(@"%s",__func__); } #pragma mark - UITableViewDataSource - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"cell"; UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if(!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text = [NSString stringWithFormat:@"%tu----%@----%@",self.index,@(indexPath.section),@(indexPath.row)]; return cell; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.index % 2 ? 50 : 2; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 80.f; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.0001; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ // Footer if (section == [self numberOfSectionsInTableView:tableView] - 1) { return [self automaticHeightForTableView:tableView]; } return 0.0001; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [UIView new]; view.backgroundColor = [UIColor orangeColor]; return view; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor redColor]; return view; } - (CGFloat)automaticHeightForTableView:(UITableView *)tableView{ // 36 segmentButtons 20 segmentTopSpace CGFloat height = self.fillHight; NSInteger section = [tableView.dataSource numberOfSectionsInTableView:tableView]; for (int i = 0; i < section; i ++) { if ([tableView.delegate respondsToSelector:@selector(tableView:heightForHeaderInSection:)]) { height += [tableView.delegate tableView:tableView heightForHeaderInSection:i]; } NSInteger row = [tableView.dataSource tableView:tableView numberOfRowsInSection:i]; for (int j= 0 ; j < row; j++) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i]; if ([tableView.delegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)]) { height += [tableView.delegate tableView:tableView heightForRowAtIndexPath:indexPath]; } if (height >= tableView.frame.size.height) { return 0.0001; } } if (i != section - 1) { if ([tableView.delegate respondsToSelector:@selector(tableView:heightForFooterInSection:)]) { height += [tableView.delegate tableView:tableView heightForFooterInSection:i]; } } } if (height >= tableView.frame.size.height) { return 0.0001; } return tableView.frame.size.height - height; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtTableViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,011
```objective-c // // ArtPullViewController.h // Demo // // Created by weijingyun on 16/10/21. // #import <UIKit/UIKit.h> @interface ArtPullViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtPullViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
45
```objective-c // // ArtPageViewController.h // BigShow1949 // // Created by big show on 2018/10/9. // #import "BaseTableViewController.h" @interface ArtPageViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtPageViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
51
```objective-c // // ArtPageViewController.m // BigShow1949 // // Created by big show on 2018/10/9. // #import "ArtPageViewController.h" @interface ArtPageViewController () @end @implementation ArtPageViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"Demo",@"ArtDefaultViewController"], @[@"",@"ArtPullViewController"], @[@"",@"ArtWholePullViewController"], @[@"headerViewScrollView",@"ArtScrollHeaderViewController"], @[@"",@"ArtChangeNavViewController"]]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtPageViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
120
```objective-c // // ArtDefaultViewController.m // Demo // // Created by weijingyun on 16/10/21. // #import "ArtPullViewController.h" #import "JYPagingView.h" #import "ArtTableViewController.h" #import "SVPullToRefresh.h" @interface ArtPullViewController ()<HHHorizontalPagingViewDelegate> @property (nonatomic, strong) HHHorizontalPagingView *pagingView; @end @implementation ArtPullViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.edgesForExtendedLayout = UIRectEdgeNone; self.view.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; [self.pagingView reload]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)showText:(NSString *)str{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate: self cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [alert dismissWithClickedButtonIndex:0 animated:YES]; }); } #pragma mark - HHHorizontalPagingViewDelegate // UIScrollView - (NSInteger)numberOfSectionsInPagingView:(HHHorizontalPagingView *)pagingView{ return 5; } - (UIScrollView *)pagingView:(HHHorizontalPagingView *)pagingView viewAtIndex:(NSInteger)index{ ArtTableViewController *vc = [[ArtTableViewController alloc] init]; [self addChildViewController:vc]; vc.index = index; vc.allowPullToRefresh = YES; vc.pullOffset = self.pagingView.pullOffset; vc.fillHight = self.pagingView.segmentTopSpace + 36; return (UIScrollView *)vc.view; } //headerView - (CGFloat)headerHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 250; } - (UIView *)headerViewInPagingView:(HHHorizontalPagingView *)pagingView{ __weak typeof(self)weakSelf = self; UIView *headerView = [[UIView alloc] init]; UIImage *image = [UIImage imageNamed:@"headerImage"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.clipsToBounds = YES; [headerView addSubview:imageView]; imageView.translatesAutoresizingMaskIntoConstraints = NO; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeRight multiplier:1 constant:0]]; [headerView whenTapped:^{ [weakSelf showText:@"headerView click"]; }]; return headerView; } //segmentButtons - (CGFloat)segmentHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 36.; } - (NSArray<UIButton*> *)segmentButtonsInPagingView:(HHHorizontalPagingView *)pagingView{ NSMutableArray *buttonArray = [NSMutableArray array]; for(int i = 0; i < 6; i++) { UIButton *segmentButton = [UIButton buttonWithType:UIButtonTypeCustom]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line"] forState:UIControlStateNormal]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line_select"] forState:UIControlStateSelected]; NSString *str = i == 5 ? @"" : [NSString stringWithFormat:@"view%@",@(i)]; [segmentButton setTitle:str forState:UIControlStateNormal]; [segmentButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; segmentButton.adjustsImageWhenHighlighted = NO; [buttonArray addObject:segmentButton]; } return [buttonArray copy]; } // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelected:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); if (selectedIndex == 5) { [self.navigationController popViewControllerAnimated:YES]; } } - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelectedSameItem:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); } // - (void)pagingView:(HHHorizontalPagingView*)pagingView didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex{ NSLog(@"%s \n %tu to %tu",__func__,aIndex,toIndex); } #pragma mark - - (HHHorizontalPagingView *)pagingView{ if (!_pagingView) { CGSize size = [UIScreen mainScreen].bounds.size; _pagingView = [[HHHorizontalPagingView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height - 64) delegate:self]; _pagingView.segmentTopSpace = 1; _pagingView.allowPullToRefresh = YES; _pagingView.segmentView.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; _pagingView.maxCacheCout = 5.; _pagingView.isGesturesSimulate = YES; _pagingView.backgroundColor = [UIColor blueColor]; [self.view addSubview:_pagingView]; } return _pagingView; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtPullViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,250
```objective-c // // ArtDefaultViewController.m // Demo // // Created by weijingyun on 16/10/21. // #import "ArtScrollHeaderViewController.h" #import "JYPagingView.h" #import "ArtTableViewController.h" @interface ArtScrollHeaderViewController ()<HHHorizontalPagingViewDelegate> @property (nonatomic, strong) HHHorizontalPagingView *pagingView; @end @implementation ArtScrollHeaderViewController - (void)viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; [self.pagingView reload]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; } - (void)viewWillAppear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:YES animated:animated]; [super viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:NO animated:animated]; [super viewWillDisappear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)showText:(NSString *)str{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate: self cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [alert dismissWithClickedButtonIndex:0 animated:YES]; }); } #pragma mark - HHHorizontalPagingViewDelegate // UIScrollView - (NSInteger)numberOfSectionsInPagingView:(HHHorizontalPagingView *)pagingView{ return 5; } - (UIScrollView *)pagingView:(HHHorizontalPagingView *)pagingView viewAtIndex:(NSInteger)index{ ArtTableViewController *vc = [[ArtTableViewController alloc] init]; [self addChildViewController:vc]; vc.index = index; vc.fillHight = self.pagingView.segmentTopSpace + 36; return (UIScrollView *)vc.view; } //headerView - (CGFloat)headerHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 250; } - (UIView *)headerViewInPagingView:(HHHorizontalPagingView *)pagingView{ UIScrollView *scrollView = [[UIScrollView alloc] init]; scrollView.backgroundColor = [UIColor purpleColor]; UIButton *but1 = [UIButton buttonWithType:UIButtonTypeCustom]; but1.frame = CGRectMake(0, 0, 100, 200); [but1 addTarget:self action:@selector(but1Click) forControlEvents:UIControlEventTouchUpInside]; but1.backgroundColor = [UIColor whiteColor]; [scrollView addSubview:but1]; UIButton *but2 = [UIButton buttonWithType:UIButtonTypeCustom]; but2.frame = CGRectMake(800, 0, 100, 200); [but2 addTarget:self action:@selector(but2Click) forControlEvents:UIControlEventTouchUpInside]; but2.backgroundColor = [UIColor whiteColor]; [scrollView addSubview:but2]; scrollView.contentSize = CGSizeMake(1000, 250); scrollView.frame = CGRectMake(0, 0, 480, 250); // UIView *headerView = [[UIView alloc] init]; // [headerView addSubview:scrollView]; return scrollView; } - (void)but1Click{ NSLog(@"%s",__func__); [self showText:@"but1Click"]; } - (void)but2Click{ NSLog(@"%s",__func__); [self showText:@"but2Click"]; } //segmentButtons - (CGFloat)segmentHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 36.; } - (NSArray<UIButton*> *)segmentButtonsInPagingView:(HHHorizontalPagingView *)pagingView{ NSMutableArray *buttonArray = [NSMutableArray array]; for(int i = 0; i < 6; i++) { UIButton *segmentButton = [UIButton buttonWithType:UIButtonTypeCustom]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line"] forState:UIControlStateNormal]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line_select"] forState:UIControlStateSelected]; NSString *str = i == 5 ? @"" : [NSString stringWithFormat:@"view%@",@(i)]; [segmentButton setTitle:str forState:UIControlStateNormal]; [segmentButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; segmentButton.adjustsImageWhenHighlighted = NO; [buttonArray addObject:segmentButton]; } return [buttonArray copy]; } // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelected:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); if (selectedIndex == 5) { [self.navigationController popViewControllerAnimated:YES]; } } - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelectedSameItem:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); } // - (void)pagingView:(HHHorizontalPagingView*)pagingView didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex{ NSLog(@"%s \n %tu to %tu",__func__,aIndex,toIndex); } #pragma mark - - (HHHorizontalPagingView *)pagingView{ if (!_pagingView) { CGSize size = [UIScreen mainScreen].bounds.size; _pagingView = [[HHHorizontalPagingView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height) delegate:self]; _pagingView.segmentTopSpace = 20; _pagingView.segmentView.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; _pagingView.maxCacheCout = 5.; _pagingView.isGesturesSimulate = YES; [self.view addSubview:_pagingView]; } return _pagingView; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtScrollHeaderViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,271
```objective-c // // ArtChangeNavViewController.m // Demo // // Created by weijingyun on 16/10/21. // #import "ArtChangeNavViewController.h" #import "JYPagingView.h" #import "ArtTableViewController.h" //#import "TESTViewController.h" @interface ArtNavView : UIView @property (nonatomic, strong) UIButton *leftBut; @end @implementation ArtNavView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self configUI]; } return self; } - (void) configUI { /* * */ self.backgroundColor = [UIColor colorWithWhite:1 alpha: 0]; UIButton *but = [UIButton buttonWithType:UIButtonTypeSystem]; but.frame = CGRectMake(0, 22, 44, 44); UIImage *buttonimage = [UIImage imageNamed:@"barbuttonicon_back"]; [but setImage:buttonimage forState:UIControlStateNormal]; but.tintColor = [UIColor colorWithWhite:0 alpha: 1]; self.leftBut = but; [self addSubview:but]; } - (void)changeAlpha:(CGFloat)alpha { self.backgroundColor = [UIColor colorWithWhite:1 alpha: alpha]; self.leftBut.tintColor = [UIColor colorWithWhite:(1 - alpha) alpha:1]; } @end @interface ArtChangeNavViewController ()<HHHorizontalPagingViewDelegate> @property (nonatomic, strong) HHHorizontalPagingView *pagingView; @property (nonatomic, strong) ArtNavView *navView; @end @implementation ArtChangeNavViewController - (void)viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; [self.pagingView reload]; /* self.edgesForExtendedLayout = UIRectEdgeNone; * - (void)pagingView:(HHHorizontalPagingView *)pagingView scrollTopOffset:(CGFloat)offset * */ self.navView = [[ArtNavView alloc] init]; CGSize size = [UIScreen mainScreen].bounds.size; self.navView.frame = CGRectMake(0, 0, size.width, 84); [self.view addSubview:self.navView]; [self.navView.leftBut addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; [self.pagingView scrollToIndex:3]; } - (void)back { [self.navigationController popViewControllerAnimated:YES]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES animated:animated]; [super viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:animated]; [super viewWillDisappear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)showText:(NSString *)str { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate: self cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [alert dismissWithClickedButtonIndex:0 animated:YES]; }); } #pragma mark - HHHorizontalPagingViewDelegate // UIScrollView - (NSInteger)numberOfSectionsInPagingView:(HHHorizontalPagingView *)pagingView { return 5; } - (UIScrollView *)pagingView:(HHHorizontalPagingView *)pagingView viewAtIndex:(NSInteger)index{ // if (index == 1) { // TESTViewController *testVC = [[TESTViewController alloc] init]; // return (UIScrollView *)testVC.view; // } ArtTableViewController *vc = [[ArtTableViewController alloc] init]; [self addChildViewController:vc]; vc.index = index; vc.fillHight = self.pagingView.segmentTopSpace + 36; return (UIScrollView *)vc.view; } //headerView - (CGFloat)headerHeightInPagingView:(HHHorizontalPagingView *)pagingView { return 250; } - (UIView *)headerViewInPagingView:(HHHorizontalPagingView *)pagingView { UIView *headerView = [[UIView alloc] init]; headerView.backgroundColor = [UIColor orangeColor]; return headerView; } - (void)but1Click{ NSLog(@"%s",__func__); [self showText:@"but1Click"]; } - (void)but2Click{ NSLog(@"%s",__func__); [self showText:@"but2Click"]; } //segmentButtons - (CGFloat)segmentHeightInPagingView:(HHHorizontalPagingView *)pagingView { return 36.; } - (NSArray<UIButton*> *)segmentButtonsInPagingView:(HHHorizontalPagingView *)pagingView { NSMutableArray *buttonArray = [NSMutableArray array]; for(int i = 0; i < 6; i++) { UIButton *segmentButton = [UIButton buttonWithType:UIButtonTypeCustom]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line"] forState:UIControlStateNormal]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line_select"] forState:UIControlStateSelected]; NSString *str = i == 5 ? @"" : [NSString stringWithFormat:@"view%@",@(i)]; [segmentButton setTitle:str forState:UIControlStateNormal]; [segmentButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; segmentButton.adjustsImageWhenHighlighted = NO; [buttonArray addObject:segmentButton]; } return [buttonArray copy]; } // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelected:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); if (selectedIndex == 5) { [self.navigationController popViewControllerAnimated:YES]; } } - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelectedSameItem:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); } // - (void)pagingView:(HHHorizontalPagingView*)pagingView didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex{ NSLog(@"%s \n %tu to %tu",__func__,aIndex,toIndex); } - (void)pagingView:(HHHorizontalPagingView *)pagingView scrollTopOffset:(CGFloat)offset { if (offset >= -84 - 36) { // > 0 return; } CGFloat fm = self.pagingView.pullOffset - 84.0 - 36; CGFloat fz = - 84 - 36 - offset; float al = 1.0 - fz / fm; al = al <= 0.05 ? 0 : al; al = al >= 0.95 ? 1 : al; // NSLog(@"__ %f __ %f __ %lf",offset,self.pagingView.pullOffset, al); [self.navView changeAlpha:al]; } #pragma mark - - (HHHorizontalPagingView *)pagingView { if (!_pagingView) { CGSize size = [UIScreen mainScreen].bounds.size; _pagingView = [[HHHorizontalPagingView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height) delegate:self]; _pagingView.segmentTopSpace = 84.; _pagingView.segmentView.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; _pagingView.maxCacheCout = 5.; // _pagingView.isGesturesSimulate = YES; [self.view addSubview:_pagingView]; } return _pagingView; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtChangeNavViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,668
```objective-c // // ArtTableViewController.h // Demo // // Created by weijingyun on 16/5/28. // #import <UIKit/UIKit.h> @interface ArtTableViewController : UIViewController @property (nonatomic, strong, readonly) UITableView *tableView; @property (nonatomic, assign) NSInteger index; @property (nonatomic, assign) BOOL allowPullToRefresh; @property (nonatomic, assign) CGFloat pullOffset; @property (nonatomic, assign) CGFloat fillHight; //segmentButtons + segmentTopSpace @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtTableViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
108
```objective-c // // ArtChangeNavViewController.h // Demo // // Created by weijingyun on 2016/12/19. // #import <UIKit/UIKit.h> @interface ArtChangeNavViewController : UIViewController @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtChangeNavViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
48
```objective-c // // HHHorizontalPagingView.h // HHHorizontalPagingView // // Created by Huanhoo on 15/7/16. // #import <UIKit/UIKit.h> #import "JYSegmentViewProtocol.h" @class HHHorizontalPagingView; // allowPullToRefresh extern NSString* kHHHorizontalScrollViewRefreshStartNotification; extern NSString* kHHHorizontalScrollViewRefreshEndNotification; // extern NSString* kHHHorizontalTakeBackRefreshEndNotification; @protocol HHHorizontalPagingViewDelegate<NSObject> // UIScrollView - (NSInteger)numberOfSectionsInPagingView:(HHHorizontalPagingView *)pagingView; - (UIScrollView *)pagingView:(HHHorizontalPagingView *)pagingView viewAtIndex:(NSInteger)index; //headerView - (CGFloat)headerHeightInPagingView:(HHHorizontalPagingView *)pagingView; - (UIView *)headerViewInPagingView:(HHHorizontalPagingView *)pagingView; #pragma mark - segmentView //segmentView - (CGFloat)segmentHeightInPagingView:(HHHorizontalPagingView *)pagingView; @optional // segmentViewHeight:pagingView: JYSegmentView - (NSArray<UIButton*> *)segmentButtonsInPagingView:(HHHorizontalPagingView *)pagingView; - (UIView<JYSegmentViewProtocol> *)segmentViewHeight:(CGFloat)height pagingView:(HHHorizontalPagingView *)pagingView; @optional // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelected:(UIView *)item atIndex:(NSInteger)selectedIndex; // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelectedSameItem:(UIView *)item atIndex:(NSInteger)selectedIndex; // - (void)pagingView:(HHHorizontalPagingView*)pagingView didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex; /* magnifyTopConstraint magnifyTopConstraint self.contentOffset */ - (void)pagingView:(HHHorizontalPagingView*)pagingView scrollTopOffset:(CGFloat)offset; @end @interface HHHorizontalPagingView : UIView /** * segment */ @property (nonatomic, assign) CGFloat segmentTopSpace; /** * NO * YES headerViewscorlView * NO : viewheaderView */ @property (nonatomic, assign) BOOL isGesturesSimulate; /** * NO * pullOffset * * * kHHHorizontalScrollViewRefreshStartNotification * kHHHorizontalScrollViewRefreshEndNotification * object ScrollView [[NSNotificationCenter defaultCenter] postNotificationName:kHHHorizontalScrollViewRefreshEndNotification object:weakSelf.tableView userInfo:nil]; * * - (void)viewWillDisappear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated * */ @property (nonatomic, assign) BOOL allowPullToRefresh; @property (nonatomic, assign, readonly) CGFloat pullOffset; // @property (nonatomic, assign) CGPoint contentOffset; @property (nonatomic, assign) BOOL isDragging; /** * 3 */ @property (nonatomic, assign) CGFloat maxCacheCout; /** * */ @property (nonatomic, strong, readonly) UIView<JYSegmentViewProtocol> *segmentView; /** * * @return */ - (instancetype)initWithFrame:(CGRect)frame delegate:(id<HHHorizontalPagingViewDelegate>) delegate; /** * * * @param pageIndex */ - (void)scrollToIndex:(NSInteger)pageIndex; /** * * * @param enable */ - (void)scrollEnable:(BOOL)enable; /** * UIScrollView * * @param index */ - (UIScrollView *)scrollViewAtIndex:(NSInteger)index; // - (void)reload; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/HHHorizontalPagingView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
785
```objective-c // // ArtDefaultViewController.m // Demo // // Created by weijingyun on 16/10/21. // #import "ArtWholePullViewController.h" #import "JYPagingView.h" #import "ArtTableViewController.h" #import "SDTimeLineRefreshHeader.h" @interface ArtWholePullViewController ()<HHHorizontalPagingViewDelegate> @property (nonatomic, strong) HHHorizontalPagingView *pagingView; @property (nonatomic, strong) SDTimeLineRefreshHeader *refreshHeader; @end @implementation ArtWholePullViewController - (void)viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; [self.pagingView reload]; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; if (self.refreshHeader != nil) { return; } self.refreshHeader = [SDTimeLineRefreshHeader refreshHeaderWithCenter:CGPointMake(40, -15)]; self.refreshHeader.scrollView = (UIView<ArtRefreshViewProtocol> *)self.pagingView; __weak typeof(_refreshHeader) weakHeader = self.refreshHeader; // 1. superview // 2. superview refreshHeader self.pagingView [self.pagingView.superview addSubview:self.refreshHeader]; [self.refreshHeader setRefreshingBlock:^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakHeader endRefreshing]; dispatch_async(dispatch_get_main_queue(), ^{ }); }); }]; } - (void)viewWillAppear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:YES animated:animated]; [super viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:NO animated:animated]; [super viewWillDisappear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)showText:(NSString *)str{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate: self cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [alert dismissWithClickedButtonIndex:0 animated:YES]; }); } #pragma mark - HHHorizontalPagingViewDelegate // UIScrollView - (NSInteger)numberOfSectionsInPagingView:(HHHorizontalPagingView *)pagingView{ return 5; } - (UIScrollView *)pagingView:(HHHorizontalPagingView *)pagingView viewAtIndex:(NSInteger)index{ ArtTableViewController *vc = [[ArtTableViewController alloc] init]; [self addChildViewController:vc]; vc.index = index; vc.fillHight = self.pagingView.segmentTopSpace + 36; return (UIScrollView *)vc.view; } //headerView - (CGFloat)headerHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 250; } - (UIView *)headerViewInPagingView:(HHHorizontalPagingView *)pagingView{ __weak typeof(self)weakSelf = self; UIView *headerView = [[UIView alloc] init]; UIImage *image = [UIImage imageNamed:@"headerImage"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.clipsToBounds = YES; [headerView addSubview:imageView]; imageView.translatesAutoresizingMaskIntoConstraints = NO; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeTop multiplier:1 constant:-150]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]]; [headerView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeRight multiplier:1 constant:0]]; headerView.backgroundColor = [UIColor orangeColor]; [headerView whenTapped:^{ [weakSelf showText:@"headerView click"]; }]; return headerView; } //segmentButtons - (CGFloat)segmentHeightInPagingView:(HHHorizontalPagingView *)pagingView{ return 36.; } - (NSArray<UIButton*> *)segmentButtonsInPagingView:(HHHorizontalPagingView *)pagingView{ NSMutableArray *buttonArray = [NSMutableArray array]; for(int i = 0; i < 6; i++) { UIButton *segmentButton = [UIButton buttonWithType:UIButtonTypeCustom]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line"] forState:UIControlStateNormal]; [segmentButton setBackgroundImage:[UIImage imageNamed:@"Home_title_line_select"] forState:UIControlStateSelected]; NSString *str = i == 5 ? @"" : [NSString stringWithFormat:@"view%@",@(i)]; [segmentButton setTitle:str forState:UIControlStateNormal]; [segmentButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; segmentButton.adjustsImageWhenHighlighted = NO; [buttonArray addObject:segmentButton]; } return [buttonArray copy]; } // segment - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelected:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); if (selectedIndex == 5) { [self.navigationController popViewControllerAnimated:YES]; } } - (void)pagingView:(HHHorizontalPagingView*)pagingView segmentDidSelectedSameItem:(UIButton *)item atIndex:(NSInteger)selectedIndex{ NSLog(@"%s",__func__); } // - (void)pagingView:(HHHorizontalPagingView*)pagingView didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex{ NSLog(@"%s \n %tu to %tu",__func__,aIndex,toIndex); } #pragma mark - - (HHHorizontalPagingView *)pagingView{ if (!_pagingView) { CGSize size = [UIScreen mainScreen].bounds.size; _pagingView = [[HHHorizontalPagingView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height) delegate:self]; _pagingView.segmentTopSpace = 20; _pagingView.segmentView.backgroundColor = [UIColor colorWithRed:242./255. green:242./255. blue:242./255. alpha:1.0]; _pagingView.maxCacheCout = 5.; _pagingView.isGesturesSimulate = YES; [self.view addSubview:_pagingView]; } return _pagingView; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/ArtWholePullViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,475
```objective-c // // JYSegmentViewProtocol.h // Demo // // Created by weijingyun on 2017/8/29. // #import <Foundation/Foundation.h> #pragma mark - SegmentViewview tag = currentIndex + pagingSubViewTag static NSInteger pagingSubViewTag = 1000; @protocol JYSegmentViewProtocol <NSObject> @property (nonatomic, copy) void(^clickBlock)(UIView *clickView); // @property (nonatomic, assign) NSInteger currenPage; // Page // @property (nonatomic, assign) NSInteger currenSelectedPage; // - (void)setSelectedPage:(NSInteger)selectedPage; @optional // view isGesturesSimulate = YES - (BOOL)findSubSegmentView:(UIView *)view; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/JYSegmentViewProtocol.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
169
```objective-c // // JYPagingView.h // Demo // // Created by weijingyun on 16/5/28. // #import "HHHorizontalPagingView.h" #import "UIView+WhenTappedBlocks.h" ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/JYPagingView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
50
```objective-c // // UIScrollView+Dragging.h // Demo // // Created by weijingyun on 16/12/3. // #import <UIKit/UIKit.h> @interface UIScrollView (Dragging) @property (nonatomic, assign) BOOL hhh_isRefresh; // @property (nonatomic, assign) BOOL hhh_startRefresh; // headView - (void)setDragging:(BOOL)dragging; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/UIScrollView+Dragging.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
86
```objective-c // // DynamicItem.m // Demo // // Created by weijingyun on 16/12/3. // #import "DynamicItem.h" @implementation DynamicItem - (instancetype)init { if (self = [super init]) { _bounds = CGRectMake(0, 0, 1, 1); } return self; } //- (void)dealloc{ // NSLog(@"%s",__func__); //} @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/DynamicItem.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
95
```objective-c // // UIView+WhenTappedBlocks.h // // Created by Jake Marsh on 3/7/11. // #import <UIKit/UIKit.h> typedef void (^JMWhenTappedBlock)(); @interface UIView (JMWhenTappedBlocks) <UIGestureRecognizerDelegate> - (void)whenTapped:(JMWhenTappedBlock)block; - (void)whenDoubleTapped:(JMWhenTappedBlock)block; - (void)whenTwoFingerTapped:(JMWhenTappedBlock)block; - (void)whenTouchedDown:(JMWhenTappedBlock)block; - (void)whenTouchedUp:(JMWhenTappedBlock)block; // head - (void)viewWasTappedPoint:(CGPoint)point; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/UIView+WhenTappedBlocks.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
163
```objective-c // // UIScrollView+Dragging.m // Demo // // Created by weijingyun on 16/12/3. // #import "UIScrollView+Dragging.h" #import <objc/runtime.h> @implementation UIScrollView (Dragging) + (void)load{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class clazz = [self class]; SEL originalSelector = @selector(isDragging); SEL swizzledSelector = @selector(swizzled_isDragging); Method originalMethod = class_getInstanceMethod(clazz, originalSelector); Method swizzledMethod = class_getInstanceMethod(clazz, swizzledSelector); BOOL success = class_addMethod(clazz, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (success) { class_replaceMethod(clazz, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); } }); } - (void)setDragging:(BOOL)dragging{ objc_setAssociatedObject(self,@selector(isDragging),[NSNumber numberWithBool:dragging],OBJC_ASSOCIATION_RETAIN); } - (BOOL)swizzled_isDragging{ BOOL dragging = [objc_getAssociatedObject(self, _cmd) boolValue]; return dragging || [self swizzled_isDragging]; } - (void)setHhh_isRefresh:(BOOL)hhh_isRefresh{ objc_setAssociatedObject(self,@selector(hhh_isRefresh),[NSNumber numberWithBool:hhh_isRefresh],OBJC_ASSOCIATION_RETAIN); } - (BOOL)hhh_isRefresh{ return [objc_getAssociatedObject(self, _cmd) boolValue]; } - (void)setHhh_startRefresh:(BOOL)hhh_startRefresh{ objc_setAssociatedObject(self,@selector(hhh_startRefresh),[NSNumber numberWithBool:hhh_startRefresh],OBJC_ASSOCIATION_RETAIN); } - (BOOL)hhh_startRefresh{ return [objc_getAssociatedObject(self, _cmd) boolValue]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/UIScrollView+Dragging.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
442
```objective-c // // UIView+WhenTappedBlocks.m // // Created by Jake Marsh on 3/7/11. // #import "UIView+WhenTappedBlocks.h" #import <objc/runtime.h> @interface UIView (JMWhenTappedBlocks_Private) - (void)runBlockForKey:(void *)blockKey; - (void)setBlock:(JMWhenTappedBlock)block forKey:(void *)blockKey; - (UITapGestureRecognizer*)addTapGestureRecognizerWithTaps:(NSUInteger) taps touches:(NSUInteger) touches selector:(SEL) selector; - (void) addRequirementToSingleTapsRecognizer:(UIGestureRecognizer*) recognizer; - (void) addRequiredToDoubleTapsRecognizer:(UIGestureRecognizer*) recognizer; @end @implementation UIView (JMWhenTappedBlocks) static char kWhenTappedBlockKey; static char kWhenDoubleTappedBlockKey; static char kWhenTwoFingerTappedBlockKey; static char kWhenTouchedDownBlockKey; static char kWhenTouchedUpBlockKey; #pragma mark - #pragma mark Set blocks - (JMWhenTappedBlock)block{ return objc_getAssociatedObject(self, &kWhenTappedBlockKey); } - (void)runBlockForKey:(void *)blockKey { JMWhenTappedBlock block = objc_getAssociatedObject(self, blockKey); if (block) block(); } - (void)setBlock:(JMWhenTappedBlock)block forKey:(void *)blockKey { self.userInteractionEnabled = YES; objc_setAssociatedObject(self, blockKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC); } #pragma mark - #pragma mark When Tapped - (void)whenTapped:(JMWhenTappedBlock)block { UITapGestureRecognizer* gesture = [self addTapGestureRecognizerWithTaps:1 touches:1 selector:@selector(viewWasTapped)]; [self addRequiredToDoubleTapsRecognizer:gesture]; [self setBlock:block forKey:&kWhenTappedBlockKey]; } - (void)whenDoubleTapped:(JMWhenTappedBlock)block { UITapGestureRecognizer* gesture = [self addTapGestureRecognizerWithTaps:2 touches:1 selector:@selector(viewWasDoubleTapped)]; [self addRequirementToSingleTapsRecognizer:gesture]; [self setBlock:block forKey:&kWhenDoubleTappedBlockKey]; } - (void)whenTwoFingerTapped:(JMWhenTappedBlock)block { [self addTapGestureRecognizerWithTaps:1 touches:2 selector:@selector(viewWasTwoFingerTapped)]; [self setBlock:block forKey:&kWhenTwoFingerTappedBlockKey]; } - (void)whenTouchedDown:(JMWhenTappedBlock)block { [self setBlock:block forKey:&kWhenTouchedDownBlockKey]; } - (void)whenTouchedUp:(JMWhenTappedBlock)block { [self setBlock:block forKey:&kWhenTouchedUpBlockKey]; } #pragma mark - #pragma mark Callbacks - (void)viewWasTapped { [self runBlockForKey:&kWhenTappedBlockKey]; } - (void)viewWasDoubleTapped { [self runBlockForKey:&kWhenDoubleTappedBlockKey]; } - (void)viewWasTwoFingerTapped { [self runBlockForKey:&kWhenTwoFingerTappedBlockKey]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; [self runBlockForKey:&kWhenTouchedDownBlockKey]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; [self runBlockForKey:&kWhenTouchedUpBlockKey]; } #pragma mark - #pragma mark Helpers - (UITapGestureRecognizer*)addTapGestureRecognizerWithTaps:(NSUInteger)taps touches:(NSUInteger)touches selector:(SEL)selector { UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:selector]; tapGesture.delegate = self; tapGesture.numberOfTapsRequired = taps; tapGesture.numberOfTouchesRequired = touches; [self addGestureRecognizer:tapGesture]; return tapGesture; } - (void) addRequirementToSingleTapsRecognizer:(UIGestureRecognizer*) recognizer { for (UIGestureRecognizer* gesture in [self gestureRecognizers]) { if ([gesture isKindOfClass:[UITapGestureRecognizer class]]) { UITapGestureRecognizer* tapGesture = (UITapGestureRecognizer*) gesture; if (tapGesture.numberOfTouchesRequired == 1 && tapGesture.numberOfTapsRequired == 1) { [tapGesture requireGestureRecognizerToFail:recognizer]; } } } } - (void) addRequiredToDoubleTapsRecognizer:(UIGestureRecognizer*) recognizer { for (UIGestureRecognizer* gesture in [self gestureRecognizers]) { if ([gesture isKindOfClass:[UITapGestureRecognizer class]]) { UITapGestureRecognizer* tapGesture = (UITapGestureRecognizer*) gesture; if (tapGesture.numberOfTouchesRequired == 2 && tapGesture.numberOfTapsRequired == 1) { [recognizer requireGestureRecognizerToFail:tapGesture]; } } } } #pragma mark - View - (void)viewWasTappedPoint:(CGPoint)point{ [self clickOnThePoint:point]; } - (BOOL)clickOnThePoint:(CGPoint)point{ if ([self.superview isKindOfClass:[UIWindow class]]) { return NO; } if (self.block) { self.block(); return YES; } __block BOOL click = NO; // [self.superview.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { // View CGPoint objPoint = [obj convertPoint:point fromView:self]; if (!CGRectContainsPoint(obj.frame, objPoint)) { // NSLog(@"-----%@",NSStringFromCGPoint(objPoint)); return; } if (self.block) { self.block(); click = YES; *stop = YES; } }]; if (!click) { return [self.superview clickOnThePoint:point]; } return click; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/UIView+WhenTappedBlocks.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
1,319
```objective-c // // DynamicItem.h // Demo // // Created by weijingyun on 16/12/3. // #import <UIKit/UIKit.h> @interface DynamicItem : NSObject<UIDynamicItem> @property (nonatomic, assign) CGPoint center; @property (nonatomic, assign, readonly) CGRect bounds; @property (nonatomic, assign) CGAffineTransform transform; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/DynamicItem.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
76
```objective-c // // JYSegmentView.h // Demo // // Created by weijingyun on 2017/8/29. // #import <UIKit/UIKit.h> #import "JYSegmentViewProtocol.h" @interface JYSegmentView : UIView<JYSegmentViewProtocol> @property (nonatomic, strong) NSArray *segmentButtons; @property (nonatomic, copy) void(^clickBlock)(UIView *clickView); @property (nonatomic, assign) CGFloat segmentBarHeight; @property (nonatomic, assign) CGSize segmentButtonSize; // @property (nonatomic, assign) NSInteger currenPage; // Page - (void)configureSegmentButtonLayout; // @property (nonatomic, assign) NSInteger currenSelectedPage; // - (void)setSelectedPage:(NSInteger)selectedPage; // view isGesturesSimulate = YES - (BOOL)findSubSegmentView:(UIView *)view; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/SegmentView/JYSegmentView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
196
```objective-c // // JYSegmentView.m // Demo // // Created by weijingyun on 2017/8/29. // #import "JYSegmentView.h" @interface JYSegmentView () @property (nonatomic, strong) NSMutableArray *segmentButtonConstraintArray; @end @implementation JYSegmentView - (void)setSegmentButtonSize:(CGSize)segmentButtonSize { _segmentButtonSize = segmentButtonSize; [self configureSegmentButtonLayout]; } - (void)configureSegmentButtonLayout { if([self.segmentButtons count] > 0) { CGFloat buttonTop = 0.f; CGFloat buttonLeft = 0.f; CGFloat buttonWidth = 0.f; CGFloat buttonHeight = 0.f; if(CGSizeEqualToSize(self.segmentButtonSize, CGSizeZero)) { buttonWidth = [[UIScreen mainScreen] bounds].size.width/(CGFloat)[self.segmentButtons count]; buttonHeight = self.segmentBarHeight; }else { buttonWidth = self.segmentButtonSize.width; buttonHeight = self.segmentButtonSize.height; buttonTop = (self.segmentBarHeight - buttonHeight)/2.f; buttonLeft = ([[UIScreen mainScreen] bounds].size.width - ((CGFloat)[self.segmentButtons count]*buttonWidth))/((CGFloat)[self.segmentButtons count]+1); } [self removeConstraints:self.segmentButtonConstraintArray]; for(int i = 0; i < [self.segmentButtons count]; i++) { UIButton *segmentButton = self.segmentButtons[i]; [segmentButton removeConstraints:self.segmentButtonConstraintArray]; segmentButton.tag = pagingSubViewTag+i; [segmentButton addTarget:self action:@selector(segmentButtonEvent:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:segmentButton]; if(i == 0) { [segmentButton setSelected:YES]; self.currenPage = 0; } segmentButton.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:segmentButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:buttonTop]; NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:segmentButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:i*buttonWidth+buttonLeft*i+buttonLeft]; NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:segmentButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:buttonWidth]; NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:segmentButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:buttonHeight]; [self.segmentButtonConstraintArray addObject:topConstraint]; [self.segmentButtonConstraintArray addObject:leftConstraint]; [self.segmentButtonConstraintArray addObject:widthConstraint]; [self.segmentButtonConstraintArray addObject:heightConstraint]; [self addConstraint:topConstraint]; [self addConstraint:leftConstraint]; [segmentButton addConstraint:widthConstraint]; [segmentButton addConstraint:heightConstraint]; if (segmentButton.currentImage) { CGFloat imageWidth = segmentButton.imageView.bounds.size.width; CGFloat labelWidth = segmentButton.titleLabel.bounds.size.width; segmentButton.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth + 5, 0, -labelWidth); segmentButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth); } } } } - (void)segmentButtonEvent:(UIButton *)segmentButton { if (self.clickBlock) { self.clickBlock(segmentButton); } } - (void)setSelectedPage:(NSInteger)selectedPage { for(UIButton *b in self.segmentButtons) { if(b.tag - pagingSubViewTag == selectedPage) { [b setSelected:YES]; }else { [b setSelected:NO]; } } self.currenSelectedPage = selectedPage; } - (BOOL)findSubSegmentView:(UIView *)view { __block BOOL find = NO; [self.segmentButtons enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if(obj == view) { find = YES; *stop = YES; } }]; return find; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/SegmentView/JYSegmentView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
920
```objective-c // // UIScrollView+SVPullToRefresh.h // // Created by Sam Vermette on 23.04.12. // // path_to_url // #import <UIKit/UIKit.h> #import <AvailabilityMacros.h> @class SVPullToRefreshView; @interface UIScrollView (SVPullToRefresh) - (void)addPullToRefreshOffset:(CGFloat)offset withActionHandler:(void (^)(void))actionHandler; - (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler; - (void)triggerPullToRefresh; - (void)triggerPullToRefreshAnimated:(BOOL)animated; @property (nonatomic, strong, readonly) SVPullToRefreshView *pullToRefreshView; @property (nonatomic, assign) BOOL showsPullToRefresh; @end enum { SVPullToRefreshStateStopped = 0, SVPullToRefreshStateTriggered, SVPullToRefreshStateLoading, SVPullToRefreshStateAll = 10 }; typedef NSUInteger SVPullToRefreshState; @interface SVPullToRefreshView : UIView @property (nonatomic, strong) UIColor *arrowColor; @property (nonatomic, strong) UIColor *textColor; @property (nonatomic, strong, readonly) UILabel *titleLabel; @property (nonatomic, strong, readonly) UILabel *subtitleLabel; @property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, readonly) SVPullToRefreshState state; - (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state; - (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state; - (void)setCustomView:(UIView *)view forState:(SVPullToRefreshState)state; - (void)startAnimating:(BOOL)animated; - (void)startAnimating; - (void)stopAnimating; - (void)stopAnimating:(BOOL)animated; // deprecated; use setSubtitle:forState: instead @property (nonatomic, strong, readonly) UILabel *dateLabel DEPRECATED_ATTRIBUTE; @property (nonatomic, strong) NSDate *lastUpdatedDate DEPRECATED_ATTRIBUTE; @property (nonatomic, strong) NSDateFormatter *dateFormatter DEPRECATED_ATTRIBUTE; // deprecated; use [self.scrollView triggerPullToRefresh] instead - (void)triggerRefresh DEPRECATED_ATTRIBUTE; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SVPullToRefresh/UIScrollView+SVPullToRefresh.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
483
```objective-c // // HHHorizontalPagingView.m // HHHorizontalPagingView // // Created by Huanhoo on 15/7/16. // #import "HHHorizontalPagingView.h" #import "DynamicItem.h" #import <objc/runtime.h> #import "UIView+WhenTappedBlocks.h" #import "UIScrollView+Dragging.h" #import "JYSegmentView.h" NSString* kHHHorizontalScrollViewRefreshStartNotification = @"kHHHorizontalScrollViewRefreshStartNotification"; NSString* kHHHorizontalScrollViewRefreshEndNotification = @"kHHHorizontalScrollViewRefreshEndNotification"; NSString* kHHHorizontalTakeBackRefreshEndNotification = @"kHHHorizontalTakeBackRefreshEndNotification"; @interface HHHorizontalPagingView () <UICollectionViewDataSource, UICollectionViewDelegate> @property (nonatomic, strong) UIView *headerView; @property (nonatomic, strong) NSMutableArray<UIScrollView *>*contentViewArray; @property (nonatomic, strong) UIView<JYSegmentViewProtocol> *segmentView; @property (nonatomic, strong) UICollectionView *horizontalCollectionView; @property (nonatomic, weak) UIScrollView *currentScrollView; @property (nonatomic, strong) NSLayoutConstraint *headerOriginYConstraint; @property (nonatomic, strong) NSLayoutConstraint *headerSizeHeightConstraint; @property (nonatomic, assign) CGFloat headerViewHeight; @property (nonatomic, assign) CGFloat segmentBarHeight; @property (nonatomic, assign) BOOL isSwitching; @property (nonatomic, strong) UIView *currentTouchView; @property (nonatomic, assign) CGPoint currentTouchViewPoint; @property (nonatomic, strong) UIView *currentTouchSubSegment; @property (nonatomic, assign) CGFloat pullOffset; @property (nonatomic, assign) BOOL isScroll;// /** * scrollView */ @property (nonatomic, strong) UIDynamicAnimator *animator; @property (nonatomic, strong) UIDynamicItemBehavior *inertialBehavior; /** * */ @property (nonatomic, weak) id<HHHorizontalPagingViewDelegate> delegate; @end @implementation HHHorizontalPagingView static void *HHHorizontalPagingViewScrollContext = &HHHorizontalPagingViewScrollContext; static void *HHHorizontalPagingViewInsetContext = &HHHorizontalPagingViewInsetContext; static void *HHHorizontalPagingViewPanContext = &HHHorizontalPagingViewPanContext; static NSString *pagingCellIdentifier = @"PagingCellIdentifier"; static NSInteger pagingScrollViewTag = 2000; #pragma mark - HHHorizontalPagingView - (instancetype)initWithFrame:(CGRect)frame delegate:(id<HHHorizontalPagingViewDelegate>) delegate{ if (self = [super initWithFrame:frame]) { self.delegate = delegate; // UICollectionView UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 0.0; layout.minimumInteritemSpacing = 0.0; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.horizontalCollectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout]; // ScrollView Cell NSInteger section = [self.delegate numberOfSectionsInPagingView:self]; [self registCellForm:0 to:section]; self.horizontalCollectionView.backgroundColor = [UIColor clearColor]; self.horizontalCollectionView.dataSource = self; self.horizontalCollectionView.delegate = self; self.horizontalCollectionView.pagingEnabled = YES; self.horizontalCollectionView.showsHorizontalScrollIndicator = NO; self.horizontalCollectionView.scrollsToTop = NO; // iOS10 NOcell if([self.horizontalCollectionView respondsToSelector:@selector(setPrefetchingEnabled:)]) { self.horizontalCollectionView.prefetchingEnabled = NO; } // iOS11 if (@available(iOS 11.0, *)) { [self.horizontalCollectionView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; } UICollectionViewFlowLayout *tempLayout = (id)self.horizontalCollectionView.collectionViewLayout; tempLayout.itemSize = self.horizontalCollectionView.frame.size; [self addSubview:self.horizontalCollectionView]; [self configureHeaderView]; [self configureSegmentView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(releaseCache) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshStart:) name:kHHHorizontalScrollViewRefreshStartNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshEnd:) name:kHHHorizontalScrollViewRefreshEndNotification object:nil]; } return self; } - (void)reload{ self.headerView = [self.delegate headerViewInPagingView:self]; self.headerViewHeight = [self.delegate headerHeightInPagingView:self]; self.segmentBarHeight = [self.delegate segmentHeightInPagingView:self]; [self configureHeaderView]; [self configureSegmentView]; // section NSInteger section = [self.delegate numberOfSectionsInPagingView:self]; [self registCellForm:0 to:section]; [self.horizontalCollectionView reloadData]; } // cell - (void)registCellForm:(NSInteger)form to:(NSInteger)to{ for (NSInteger i = form; i < to; i ++) { [self.horizontalCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:[self cellReuseIdentifierForIndex:i]]; } } - (NSString *)cellReuseIdentifierForIndex:(NSInteger)aIndex{ return [NSString stringWithFormat:@"%@_%tu",pagingCellIdentifier,aIndex]; } - (CGFloat)pullOffset{ if (_pullOffset == 0) { _pullOffset = [self.delegate headerHeightInPagingView:self] + [self.delegate segmentHeightInPagingView:self]; } return _pullOffset; } - (void)scrollToIndex:(NSInteger)pageIndex { UIView *clickView = [self.segmentView viewWithTag:pagingSubViewTag + pageIndex]; [self segmentViewEvent:clickView]; } - (void)scrollEnable:(BOOL)enable { if(enable) { self.segmentView.userInteractionEnabled = YES; self.horizontalCollectionView.scrollEnabled = YES; }else { self.segmentView.userInteractionEnabled = NO; self.horizontalCollectionView.scrollEnabled = NO; } } - (void)configureHeaderView { [self.headerView removeFromSuperview]; if(self.headerView) { self.headerView.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:self.headerView]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.headerView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.headerView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:0]]; self.headerOriginYConstraint = [NSLayoutConstraint constraintWithItem:self.headerView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:0]; [self addConstraint:self.headerOriginYConstraint]; self.headerSizeHeightConstraint = [NSLayoutConstraint constraintWithItem:self.headerView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:self.headerViewHeight]; [self.headerView addConstraint:self.headerSizeHeightConstraint]; [self addGestureRecognizerAtHeaderView]; } } - (void)configureSegmentView { [self.segmentView removeFromSuperview]; self.segmentView = nil; if(self.segmentView) { self.segmentView.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:self.segmentView]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.segmentView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.segmentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:0]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.segmentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headerView ? : self attribute:self.headerView ? NSLayoutAttributeBottom : NSLayoutAttributeTop multiplier:1 constant:0]]; [self.segmentView addConstraint:[NSLayoutConstraint constraintWithItem:self.segmentView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:self.segmentBarHeight]]; } } - (UIScrollView *)scrollViewAtIndex:(NSInteger)index{ __block UIScrollView *scrollView = nil; [self.contentViewArray enumerateObjectsUsingBlock:^(UIScrollView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.tag == pagingScrollViewTag + index) { scrollView = obj; *stop = YES; } }]; if (scrollView == nil) { scrollView = [self.delegate pagingView:self viewAtIndex:index]; if ([scrollView isKindOfClass:[UITableView class]]) { UITableView *tableView = (UITableView *)scrollView; tableView.sectionHeaderHeight = 0.; tableView.sectionFooterHeight = 0.; tableView.estimatedRowHeight = 0.; tableView.estimatedSectionFooterHeight = 0.; tableView.estimatedSectionHeaderHeight = 0.; } if (@available(iOS 11.0, *)) { [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; } [self configureContentView:scrollView]; scrollView.tag = pagingScrollViewTag + index; [self.contentViewArray addObject:scrollView]; } return scrollView; } - (void)configureContentView:(UIScrollView *)scrollView{ [scrollView setContentInset:UIEdgeInsetsMake(self.headerViewHeight+self.segmentBarHeight, 0., scrollView.contentInset.bottom, 0.)]; scrollView.alwaysBounceVertical = YES; scrollView.showsVerticalScrollIndicator = NO; scrollView.contentOffset = CGPointMake(0., -self.headerViewHeight-self.segmentBarHeight); [scrollView.panGestureRecognizer addObserver:self forKeyPath:NSStringFromSelector(@selector(state)) options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:&HHHorizontalPagingViewPanContext]; [scrollView addObserver:self forKeyPath:NSStringFromSelector(@selector(contentOffset)) options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:&HHHorizontalPagingViewScrollContext]; [scrollView addObserver:self forKeyPath:NSStringFromSelector(@selector(contentInset)) options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:&HHHorizontalPagingViewInsetContext]; if (scrollView == nil) { self.currentScrollView = scrollView; } } - (UIView<JYSegmentViewProtocol> *)segmentView { if(!_segmentView) { CGFloat height = [self.delegate segmentHeightInPagingView:self]; if ([self.delegate respondsToSelector:@selector(segmentViewHeight:pagingView:)]) { _segmentView = [self.delegate segmentViewHeight:height pagingView:self]; }else { _segmentView = [[JYSegmentView alloc] init]; JYSegmentView *view = (JYSegmentView *)_segmentView; view.segmentButtons = [self.delegate segmentButtonsInPagingView:self]; view.segmentBarHeight = height; [view configureSegmentButtonLayout]; } __weak typeof(self)weakSelf = self; _segmentView.clickBlock = ^(UIView *view) { [weakSelf segmentViewEvent:view]; }; } return _segmentView; } - (void)segmentViewEvent:(UIView *)segmentView { NSInteger clickIndex = segmentView.tag - pagingSubViewTag; if (clickIndex >= [self.delegate numberOfSectionsInPagingView:self]) { if ([self.delegate respondsToSelector:@selector(pagingView:segmentDidSelected:atIndex:)]) { [self.delegate pagingView:self segmentDidSelected:segmentView atIndex:clickIndex]; } return; } // if (clickIndex == self.segmentView.currenPage) { if ([self.delegate respondsToSelector:@selector(pagingView:segmentDidSelectedSameItem:atIndex:)]) { [self.delegate pagingView:self segmentDidSelectedSameItem:segmentView atIndex:clickIndex]; } return; } // [self.horizontalCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:clickIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO]; if(self.currentScrollView.contentOffset.y<-(self.headerViewHeight+self.segmentBarHeight)) { [self.currentScrollView setContentOffset:CGPointMake(self.currentScrollView.contentOffset.x, -(self.headerViewHeight+self.segmentBarHeight)) animated:NO]; }else { [self.currentScrollView setContentOffset:self.currentScrollView.contentOffset animated:NO]; } if ([self.delegate respondsToSelector:@selector(pagingView:segmentDidSelected:atIndex:)]) { [self.delegate pagingView:self segmentDidSelected:segmentView atIndex:clickIndex]; } // [self didSwitchIndex:self.segmentView.currenPage to:clickIndex]; } - (void)adjustOffsetContentView:(UIScrollView *)scrollView { self.isSwitching = YES; CGFloat headerViewDisplayHeight = self.headerViewHeight + self.headerView.frame.origin.y; [scrollView layoutIfNeeded]; if (headerViewDisplayHeight != self.segmentTopSpace) {// [scrollView setContentOffset:CGPointMake(0, -headerViewDisplayHeight - self.segmentBarHeight)]; }else if(scrollView.contentOffset.y < -self.segmentBarHeight) { [scrollView setContentOffset:CGPointMake(0, -headerViewDisplayHeight-self.segmentBarHeight)]; }else { // self.segmentTopSpace [scrollView setContentOffset:CGPointMake(0, scrollView.contentOffset.y-headerViewDisplayHeight + self.segmentTopSpace)]; } if ([scrollView.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)]) { [scrollView.delegate scrollViewDidEndDragging:scrollView willDecelerate:NO]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0)), dispatch_get_main_queue(), ^{ self.isSwitching = NO; }); } #pragma mark - headerView - (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event { if(point.x < 10) { return NO; } return YES; } - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *view = [super hitTest:point withEvent:event]; // BUG -[__NSCFType isDescendantOfView:]: unrecognized selector sent to instance 0x9dd30e0 if (![view isKindOfClass:[UIView class]]) { return nil; } if (self.isGesturesSimulate) { return view; } // headerViewcurrentScrollView if (self.currentScrollView.hhh_isRefresh) { return view; } if ([view isDescendantOfView:self.headerView] || [view isDescendantOfView:self.segmentView]) { self.horizontalCollectionView.scrollEnabled = NO; self.currentTouchView = nil; self.currentTouchSubSegment = [self.segmentView findSubSegmentView:view] ? view : nil; if(!self.currentTouchSubSegment) { self.currentTouchView = view; self.currentTouchViewPoint = [self convertPoint:point toView:self.currentTouchView]; }else { return view; } return self.currentScrollView; } return view; } - (void)addGestureRecognizerAtHeaderView{ if (self.isGesturesSimulate == NO) { return; } UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; pan.delegate = self; [self.headerView addGestureRecognizer:pan]; } - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)gestureRecognizer; CGPoint point = [pan translationInView:self.headerView]; if (fabs(point.y) <= fabs(point.x)) { return NO; } } return YES; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; } - (void)pan:(UIPanGestureRecognizer*)pan{ // headerView if (self.currentScrollView.hhh_isRefresh) { return; } // self.isDragging = !(pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateFailed); [self.currentScrollView setDragging:self.isDragging]; // CGPoint point = [pan translationInView:self.headerView]; CGPoint contentOffset = self.currentScrollView.contentOffset; CGFloat border = - self.headerViewHeight - [self.delegate segmentHeightInPagingView:self]; NSLog(@"border = %f", border); CGFloat offsety = contentOffset.y - point.y * (1/contentOffset.y * border * 0.8); self.currentScrollView.contentOffset = CGPointMake(contentOffset.x, offsety); NSLog(@"contentOffset.y = %f", contentOffset.y); if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateFailed) { if (contentOffset.y <= border) { // if (self.currentScrollView.hhh_isRefresh) { return; } // [UIView animateWithDuration:0.35 animations:^{ self.currentScrollView.contentOffset = CGPointMake(contentOffset.x, border); [self layoutIfNeeded]; }]; }else{ // CGFloat velocity = [pan velocityInView:self.headerView].y; [self deceleratingAnimator:velocity]; } } // [pan setTranslation:CGPointZero inView:self.headerView]; } - (void)deceleratingAnimator:(CGFloat)velocity{ if (self.inertialBehavior != nil) { [self.animator removeBehavior:self.inertialBehavior]; } DynamicItem *item = [[DynamicItem alloc] init]; item.center = CGPointMake(0, 0); // velocity UIDynamicItemBehavior *inertialBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[ item ]]; [inertialBehavior addLinearVelocity:CGPointMake(0, velocity * 0.025) forItem:item]; // 2.0 inertialBehavior.resistance = 2; __weak typeof(self)weakSelf = self; CGFloat maxOffset = self.currentScrollView.contentSize.height - self.currentScrollView.bounds.size.height; inertialBehavior.action = ^{ CGPoint contentOffset = weakSelf.currentScrollView.contentOffset; CGFloat speed = [weakSelf.inertialBehavior linearVelocityForItem:item].y; CGFloat offset = contentOffset.y - speed; if (speed >= -0.2) { [weakSelf.animator removeBehavior:weakSelf.inertialBehavior]; weakSelf.inertialBehavior = nil; }else if (offset >= maxOffset){ [weakSelf.animator removeBehavior:weakSelf.inertialBehavior]; weakSelf.inertialBehavior = nil; offset = maxOffset; // scrollView [UIView animateWithDuration:0.2 animations:^{ weakSelf.currentScrollView.contentOffset = CGPointMake(contentOffset.x, offset - speed); [weakSelf layoutIfNeeded]; } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 animations:^{ weakSelf.currentScrollView.contentOffset = CGPointMake(contentOffset.x, offset); [weakSelf layoutIfNeeded]; }]; }]; }else{ weakSelf.currentScrollView.contentOffset = CGPointMake(contentOffset.x, offset); } }; self.inertialBehavior = inertialBehavior; [self.animator addBehavior:inertialBehavior]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.delegate numberOfSectionsInPagingView:self]; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { self.isSwitching = YES; NSString* key = [self cellReuseIdentifierForIndex:indexPath.row]; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:key forIndexPath:indexPath]; UIScrollView *v = [self scrollViewAtIndex:indexPath.row]; // cellscrollView if (cell.contentView.tag != v.tag) { cell.backgroundColor = [UIColor clearColor]; for(UIView *v in cell.contentView.subviews) { [v removeFromSuperview]; } cell.tag = v.tag; UIViewController *vc = [self viewControllerForView:v]; // v [cell.contentView addSubview:vc.view]; cell.tag = v.tag; vc.view.translatesAutoresizingMaskIntoConstraints = NO; [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:vc.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:vc.view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:vc.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]]; [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:vc.view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1 constant:0]]; [cell layoutIfNeeded]; } self.currentScrollView = v; [self adjustOffsetContentView:v]; return cell; } #pragma mark - Observer - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(__unused id)object change:(NSDictionary *)change context:(void *)context { if(context == &HHHorizontalPagingViewPanContext) { self.isDragging = YES; self.horizontalCollectionView.scrollEnabled = YES; UIGestureRecognizerState state = [change[NSKeyValueChangeNewKey] integerValue]; //failed if(state == UIGestureRecognizerStateFailed) { if(self.currentTouchSubSegment) { [self segmentViewEvent:self.currentTouchSubSegment]; }else if(self.currentTouchView) { [self.currentTouchView viewWasTappedPoint:self.currentTouchViewPoint]; } self.currentTouchView = nil; self.currentTouchSubSegment = nil; }else if (state == UIGestureRecognizerStateCancelled || state == UIGestureRecognizerStateEnded) { self.isDragging = NO; } }else if (context == &HHHorizontalPagingViewScrollContext) { self.currentTouchView = nil; self.currentTouchSubSegment = nil; if (self.isSwitching) { return; } // ScrollView if (object != self.currentScrollView) { return; } CGFloat oldOffsetY = [change[NSKeyValueChangeOldKey] CGPointValue].y; CGFloat newOffsetY = [change[NSKeyValueChangeNewKey] CGPointValue].y; CGFloat deltaY = newOffsetY - oldOffsetY; NSLog(@"deltaY ====== %f", deltaY); CGFloat headerViewHeight = self.headerViewHeight; CGFloat headerDisplayHeight = self.headerViewHeight+self.headerOriginYConstraint.constant; CGFloat py = 0; if(deltaY >= 0) { // if(headerDisplayHeight - deltaY <= self.segmentTopSpace) { py = -headerViewHeight+self.segmentTopSpace; }else { py = self.headerOriginYConstraint.constant - deltaY; } if(headerDisplayHeight <= self.segmentTopSpace) { py = -headerViewHeight+self.segmentTopSpace; } if (!self.allowPullToRefresh) { self.headerOriginYConstraint.constant = py; }else if (py < 0 && !self.currentScrollView.hhh_isRefresh && !self.currentScrollView.hhh_startRefresh) { self.headerOriginYConstraint.constant = py; }else{ if (self.currentScrollView.contentOffset.y >= -headerViewHeight - self.segmentBarHeight) { self.currentScrollView.hhh_startRefresh = NO; } self.headerOriginYConstraint.constant = 0; } }else { // if (headerDisplayHeight+self.segmentBarHeight < -newOffsetY) { py = -self.headerViewHeight-self.segmentBarHeight-self.currentScrollView.contentOffset.y; if (!self.allowPullToRefresh) { self.headerOriginYConstraint.constant = py; }else if (py <0) { self.headerOriginYConstraint.constant = py; } else{ self.currentScrollView.hhh_startRefresh = YES; self.headerOriginYConstraint.constant = 0; } } } self.contentOffset = self.currentScrollView.contentOffset; if ([self.delegate respondsToSelector:@selector(pagingView:scrollTopOffset:)]) { [self.delegate pagingView:self scrollTopOffset:self.contentOffset.y]; } }else if(context == &HHHorizontalPagingViewInsetContext) { if(self.allowPullToRefresh || self.currentScrollView.contentOffset.y > -self.segmentBarHeight) { return; } [UIView animateWithDuration:0.2 animations:^{ self.headerOriginYConstraint.constant = -self.headerViewHeight-self.segmentBarHeight-self.currentScrollView.contentOffset.y; [self layoutIfNeeded]; [self.headerView layoutIfNeeded]; [self.segmentView layoutIfNeeded]; }]; } } - (void)refreshStart:(NSNotification *)notification{ UIScrollView *obj = notification.object; [self.contentViewArray enumerateObjectsUsingBlock:^(UIScrollView * _Nonnull scrollView, NSUInteger idx, BOOL * _Nonnull stop) { if (obj == scrollView) { scrollView.hhh_startRefresh = YES; scrollView.hhh_isRefresh = YES; *stop = YES; } }]; } - (void)refreshEnd:(NSNotification *)notification{ UIScrollView *obj = notification.object; [self.contentViewArray enumerateObjectsUsingBlock:^(UIScrollView * _Nonnull scrollView, NSUInteger idx, BOOL * _Nonnull stop) { if (obj == scrollView) { scrollView.hhh_startRefresh = NO; scrollView.hhh_isRefresh = NO; [scrollView setDragging:NO]; *stop = YES; } }]; } // - (void)didSwitchIndex:(NSInteger)aIndex to:(NSInteger)toIndex{ self.segmentView.currenPage = toIndex; self.currentScrollView = [self scrollViewAtIndex:toIndex]; if (aIndex == toIndex) { return; } UIScrollView *oldScrollView = [self scrollViewAtIndex:aIndex]; if (oldScrollView.hhh_isRefresh) { oldScrollView.hhh_startRefresh = NO; oldScrollView.hhh_isRefresh = NO; [oldScrollView setDragging:NO]; [[NSNotificationCenter defaultCenter] postNotificationName:kHHHorizontalTakeBackRefreshEndNotification object:[self scrollViewAtIndex:aIndex]]; } [self.segmentView setSelectedPage:toIndex]; [self removeCacheScrollView]; if ([self.delegate respondsToSelector:@selector(pagingView:didSwitchIndex:to:)]) { [self.delegate pagingView:self didSwitchIndex:aIndex to:toIndex]; } } #pragma mark - UIScrollViewDelegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { self.isScroll = YES; CGFloat offsetpage = scrollView.contentOffset.x/[[UIScreen mainScreen] bounds].size.width; CGFloat py = fabs((int)offsetpage - offsetpage); if ( py <= 0.3 || py >= 0.7) { return; } NSInteger currentPage = self.segmentView.currenSelectedPage; if (offsetpage - currentPage > 0) { if (py > 0.55) { [self.segmentView setSelectedPage:currentPage + 1]; } }else{ if (py < 0.45) { [self.segmentView setSelectedPage:currentPage - 1]; } } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { if (!self.isScroll) { // return; } self.isScroll = NO; NSInteger currentPage = scrollView.contentOffset.x/[[UIScreen mainScreen] bounds].size.width; [self didSwitchIndex:self.segmentView.currenPage to:currentPage]; } - (void)removeCacheScrollView{ if (self.contentViewArray.count <= self.maxCacheCout) { return; } [self releaseCache]; } - (void)releaseCache{ NSInteger currentCount = self.currentScrollView.tag; [self.contentViewArray enumerateObjectsUsingBlock:^(UIScrollView * _Nonnull scrollView, NSUInteger idx, BOOL * _Nonnull stop) { if (labs(scrollView.tag - currentCount) > 1) { [self removeScrollView:scrollView]; } }]; } - (void)removeScrollView:(UIScrollView *)scrollView{ [self removeObserverFor:scrollView]; [self.contentViewArray removeObject:scrollView]; UIViewController *vc = [self viewControllerForView:scrollView]; vc.view.tag = 0; scrollView.superview.tag = 0; vc.view.superview.tag = 0; [scrollView removeFromSuperview]; [vc.view removeFromSuperview]; [vc removeFromParentViewController]; } - (UIViewController *)viewControllerForView:(UIView *)view { for (UIView* next = view; next; next = next.superview) { UIResponder *nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return (UIViewController *)nextResponder; } } return nil; } - (void)removeObserverFor:(UIScrollView *)scrollView{ [scrollView.panGestureRecognizer removeObserver:self forKeyPath:NSStringFromSelector(@selector(state)) context:&HHHorizontalPagingViewPanContext]; [scrollView removeObserver:self forKeyPath:NSStringFromSelector(@selector(contentOffset)) context:&HHHorizontalPagingViewScrollContext]; [scrollView removeObserver:self forKeyPath:NSStringFromSelector(@selector(contentInset)) context:&HHHorizontalPagingViewInsetContext]; } - (void)dealloc { [self.contentViewArray enumerateObjectsUsingBlock:^(UIScrollView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [self removeObserverFor:obj]; }]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - - (UIDynamicAnimator *)animator{ if (!_animator) { _animator = [[UIDynamicAnimator alloc] init]; } return _animator; } - (NSMutableArray<UIScrollView *> *)contentViewArray{ if (!_contentViewArray) { _contentViewArray = [[NSMutableArray alloc] init]; } return _contentViewArray; } - (CGFloat)maxCacheCout{ if (_maxCacheCout == 0) { _maxCacheCout = 3; } return _maxCacheCout; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/HHHorizontalPagingView/HHHorizontalPagingView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
6,474
```objective-c // // SVPullToRefresh.h // SVPullToRefreshDemo // // Created by Sam Vermette on 23.04.12. // // path_to_url // // this header file is provided for backwards compatibility and will be removed in the future // here's how you should import SVPullToRefresh now: #import "UIScrollView+SVPullToRefresh.h" #import "UIScrollView+SVInfiniteScrolling.h" ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SVPullToRefresh/SVPullToRefresh.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
95
```objective-c // // UIScrollView+SVInfiniteScrolling.h // // Created by Sam Vermette on 23.04.12. // // path_to_url // #import <UIKit/UIKit.h> @class SVInfiniteScrollingView; @interface UIScrollView (SVInfiniteScrolling) - (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler; - (void)triggerInfiniteScrolling; @property (nonatomic, strong, readonly) SVInfiniteScrollingView *infiniteScrollingView; @property (nonatomic, assign) BOOL showsInfiniteScrolling; @end enum { SVInfiniteScrollingStateStopped = 0, SVInfiniteScrollingStateTriggered, SVInfiniteScrollingStateLoading, SVInfiniteScrollingStateAll = 10 }; typedef NSUInteger SVInfiniteScrollingState; @interface SVInfiniteScrollingView : UIView @property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, readonly) SVInfiniteScrollingState state; @property (nonatomic, readwrite) BOOL enabled; - (void)setCustomView:(UIView *)view forState:(SVInfiniteScrollingState)state; - (void)startAnimating; - (void)stopAnimating; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
265
```objective-c // // UIScrollView+SVInfiniteScrolling.m // // Created by Sam Vermette on 23.04.12. // // path_to_url // #import <QuartzCore/QuartzCore.h> #import "UIScrollView+SVInfiniteScrolling.h" static CGFloat const SVInfiniteScrollingViewHeight = 60; @interface SVInfiniteScrollingDotView : UIView @property (nonatomic, strong) UIColor *arrowColor; @end @interface SVInfiniteScrollingView () @property (nonatomic, copy) void (^infiniteScrollingHandler)(void); @property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView; @property (nonatomic, readwrite) SVInfiniteScrollingState state; @property (nonatomic, strong) NSMutableArray *viewForState; @property (nonatomic, weak) UIScrollView *scrollView; @property (nonatomic, readwrite) CGFloat originalBottomInset; @property (nonatomic, assign) BOOL wasTriggeredByUser; @property (nonatomic, assign) BOOL isObserving; - (void)resetScrollViewContentInset; - (void)setScrollViewContentInsetForInfiniteScrolling; - (void)setScrollViewContentInset:(UIEdgeInsets)insets; @end #pragma mark - UIScrollView (SVInfiniteScrollingView) #import <objc/runtime.h> static char UIScrollViewInfiniteScrollingView; UIEdgeInsets scrollViewOriginalContentInsets; @implementation UIScrollView (SVInfiniteScrolling) @dynamic infiniteScrollingView; - (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler { if(!self.infiniteScrollingView) { SVInfiniteScrollingView *view = [[SVInfiniteScrollingView alloc] initWithFrame:CGRectMake(0, self.contentSize.height, self.bounds.size.width, SVInfiniteScrollingViewHeight)]; view.infiniteScrollingHandler = actionHandler; view.scrollView = self; [self addSubview:view]; view.originalBottomInset = self.contentInset.bottom; self.infiniteScrollingView = view; self.showsInfiniteScrolling = YES; } } - (void)triggerInfiniteScrolling { self.infiniteScrollingView.state = SVInfiniteScrollingStateTriggered; [self.infiniteScrollingView startAnimating]; } - (void)setInfiniteScrollingView:(SVInfiniteScrollingView *)infiniteScrollingView { [self willChangeValueForKey:@"UIScrollViewInfiniteScrollingView"]; objc_setAssociatedObject(self, &UIScrollViewInfiniteScrollingView, infiniteScrollingView, OBJC_ASSOCIATION_ASSIGN); [self didChangeValueForKey:@"UIScrollViewInfiniteScrollingView"]; } - (SVInfiniteScrollingView *)infiniteScrollingView { return objc_getAssociatedObject(self, &UIScrollViewInfiniteScrollingView); } - (void)setShowsInfiniteScrolling:(BOOL)showsInfiniteScrolling { self.infiniteScrollingView.hidden = !showsInfiniteScrolling; if(!showsInfiniteScrolling) { if (self.infiniteScrollingView.isObserving) { [self removeObserver:self.infiniteScrollingView forKeyPath:@"contentOffset"]; [self removeObserver:self.infiniteScrollingView forKeyPath:@"contentSize"]; [self.infiniteScrollingView resetScrollViewContentInset]; self.infiniteScrollingView.isObserving = NO; } } else { if (!self.infiniteScrollingView.isObserving) { [self addObserver:self.infiniteScrollingView forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self.infiniteScrollingView forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; [self.infiniteScrollingView setScrollViewContentInsetForInfiniteScrolling]; self.infiniteScrollingView.isObserving = YES; [self.infiniteScrollingView setNeedsLayout]; self.infiniteScrollingView.frame = CGRectMake(0, self.contentSize.height, self.infiniteScrollingView.bounds.size.width, SVInfiniteScrollingViewHeight); } } } - (BOOL)showsInfiniteScrolling { return !self.infiniteScrollingView.hidden; } @end #pragma mark - SVInfiniteScrollingView @implementation SVInfiniteScrollingView // public properties @synthesize infiniteScrollingHandler, activityIndicatorViewStyle; @synthesize state = _state; @synthesize scrollView = _scrollView; @synthesize activityIndicatorView = _activityIndicatorView; - (id)initWithFrame:(CGRect)frame { if(self = [super initWithFrame:frame]) { // default styling values self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; self.autoresizingMask = UIViewAutoresizingFlexibleWidth; self.state = SVInfiniteScrollingStateStopped; self.enabled = YES; self.viewForState = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", nil]; } return self; } - (void)willMoveToSuperview:(UIView *)newSuperview { if (self.superview && newSuperview == nil) { UIScrollView *scrollView = (UIScrollView *)self.superview; if (scrollView.showsInfiniteScrolling) { if (self.isObserving) { [scrollView removeObserver:self forKeyPath:@"contentOffset"]; [scrollView removeObserver:self forKeyPath:@"contentSize"]; self.isObserving = NO; } } } } - (void)layoutSubviews { self.activityIndicatorView.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); } #pragma mark - Scroll View - (void)resetScrollViewContentInset { UIEdgeInsets currentInsets = self.scrollView.contentInset; currentInsets.bottom = self.originalBottomInset; [self setScrollViewContentInset:currentInsets]; } - (void)setScrollViewContentInsetForInfiniteScrolling { UIEdgeInsets currentInsets = self.scrollView.contentInset; currentInsets.bottom = self.originalBottomInset + SVInfiniteScrollingViewHeight; [self setScrollViewContentInset:currentInsets]; } - (void)setScrollViewContentInset:(UIEdgeInsets)contentInset { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState animations:^{ self.scrollView.contentInset = contentInset; } completion:NULL]; } #pragma mark - Observing - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([keyPath isEqualToString:@"contentOffset"]) [self scrollViewDidScroll:[[change valueForKey:NSKeyValueChangeNewKey] CGPointValue]]; else if([keyPath isEqualToString:@"contentSize"]) { [self layoutSubviews]; self.frame = CGRectMake(0, self.scrollView.contentSize.height, self.bounds.size.width, SVInfiniteScrollingViewHeight); } } - (void)scrollViewDidScroll:(CGPoint)contentOffset { if(self.state != SVInfiniteScrollingStateLoading && self.enabled) { CGFloat scrollViewContentHeight = self.scrollView.contentSize.height; CGFloat scrollOffsetThreshold = scrollViewContentHeight-self.scrollView.bounds.size.height; if(!self.scrollView.isDragging && self.state == SVInfiniteScrollingStateTriggered) self.state = SVInfiniteScrollingStateLoading; else if(contentOffset.y > scrollOffsetThreshold && self.state == SVInfiniteScrollingStateStopped && self.scrollView.isDragging) self.state = SVInfiniteScrollingStateTriggered; else if(contentOffset.y < scrollOffsetThreshold && self.state != SVInfiniteScrollingStateStopped) self.state = SVInfiniteScrollingStateStopped; } } #pragma mark - Getters - (UIActivityIndicatorView *)activityIndicatorView { if(!_activityIndicatorView) { _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; _activityIndicatorView.hidesWhenStopped = YES; [self addSubview:_activityIndicatorView]; } return _activityIndicatorView; } - (UIActivityIndicatorViewStyle)activityIndicatorViewStyle { return self.activityIndicatorView.activityIndicatorViewStyle; } #pragma mark - Setters - (void)setCustomView:(UIView *)view forState:(SVInfiniteScrollingState)state { id viewPlaceholder = view; if(!viewPlaceholder) viewPlaceholder = @""; if(state == SVInfiniteScrollingStateAll) [self.viewForState replaceObjectsInRange:NSMakeRange(0, 3) withObjectsFromArray:@[viewPlaceholder, viewPlaceholder, viewPlaceholder]]; else [self.viewForState replaceObjectAtIndex:state withObject:viewPlaceholder]; self.state = self.state; } - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)viewStyle { self.activityIndicatorView.activityIndicatorViewStyle = viewStyle; } #pragma mark - - (void)triggerRefresh { self.state = SVInfiniteScrollingStateTriggered; self.state = SVInfiniteScrollingStateLoading; } - (void)startAnimating{ self.state = SVInfiniteScrollingStateLoading; } - (void)stopAnimating { self.state = SVInfiniteScrollingStateStopped; } - (void)setState:(SVInfiniteScrollingState)newState { if(_state == newState) return; SVInfiniteScrollingState previousState = _state; _state = newState; for(id otherView in self.viewForState) { if([otherView isKindOfClass:[UIView class]]) [otherView removeFromSuperview]; } id customView = [self.viewForState objectAtIndex:newState]; BOOL hasCustomView = [customView isKindOfClass:[UIView class]]; if(hasCustomView) { [self addSubview:customView]; CGRect viewBounds = [customView bounds]; CGPoint origin = CGPointMake(roundf((self.bounds.size.width-viewBounds.size.width)/2), roundf((self.bounds.size.height-viewBounds.size.height)/2)); [customView setFrame:CGRectMake(origin.x, origin.y, viewBounds.size.width, viewBounds.size.height)]; } else { CGRect viewBounds = [self.activityIndicatorView bounds]; CGPoint origin = CGPointMake(roundf((self.bounds.size.width-viewBounds.size.width)/2), roundf((self.bounds.size.height-viewBounds.size.height)/2)); [self.activityIndicatorView setFrame:CGRectMake(origin.x, origin.y, viewBounds.size.width, viewBounds.size.height)]; switch (newState) { case SVInfiniteScrollingStateStopped: [self.activityIndicatorView stopAnimating]; break; case SVInfiniteScrollingStateTriggered: break; case SVInfiniteScrollingStateLoading: [self.activityIndicatorView startAnimating]; break; } } if(previousState == SVInfiniteScrollingStateTriggered && newState == SVInfiniteScrollingStateLoading && self.infiniteScrollingHandler && self.enabled) self.infiniteScrollingHandler(); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
2,293
```objective-c // // SDBaseRefreshView.h // #import <UIKit/UIKit.h> @protocol ArtRefreshViewProtocol <NSObject> @property (nonatomic, assign) CGPoint contentOffset; @property (nonatomic, assign) BOOL isDragging; @end UIKIT_EXTERN NSString *const kSDBaseRefreshViewObserveKeyPath; typedef enum { SDWXRefreshViewStateNormal, SDWXRefreshViewStateWillRefresh, SDWXRefreshViewStateRefreshing, } SDWXRefreshViewState; @interface SDBaseRefreshView : UIView // strong scrollView @property (nonatomic, strong) UIView<ArtRefreshViewProtocol> *scrollView; - (void)endRefreshing; @property (nonatomic, assign) UIEdgeInsets scrollViewOriginalInsets; @property (nonatomic, assign) SDWXRefreshViewState refreshState; @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SDRefresh/SDBaseRefreshView.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
158
```objective-c // // SDBaseRefreshView.m // #import "SDBaseRefreshView.h" NSString *const kSDBaseRefreshViewObserveKeyPath = @"contentOffset"; @implementation SDBaseRefreshView - (void)setScrollView:(UIView<ArtRefreshViewProtocol> *)scrollView { _scrollView = scrollView; [scrollView addObserver:self forKeyPath:kSDBaseRefreshViewObserveKeyPath options:NSKeyValueObservingOptionNew context:nil]; } - (void)willMoveToSuperview:(UIView *)newSuperview { if (!newSuperview) { [self.scrollView removeObserver:self forKeyPath:kSDBaseRefreshViewObserveKeyPath]; } } - (void)endRefreshing { self.refreshState = SDWXRefreshViewStateNormal; } - (void)dealloc{ NSLog(@"%s",__func__); } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { // } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SDRefresh/SDBaseRefreshView.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
218
```objective-c // // SDTimeLineRefreshHeader.h // #import <UIKit/UIKit.h> #import "SDBaseRefreshView.h" @interface SDTimeLineRefreshHeader : SDBaseRefreshView + (instancetype)refreshHeaderWithCenter:(CGPoint)center; @property (nonatomic, copy) void(^refreshingBlock)(); @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SDRefresh/SDTimeLineRefreshHeader.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
68
```objective-c // // UIScrollView+SVPullToRefresh.m // // Created by Sam Vermette on 23.04.12. // // path_to_url // #import <QuartzCore/QuartzCore.h> #import "UIScrollView+SVPullToRefresh.h" //fequalzro() from path_to_url #define fequalzero(a) (fabs(a) < FLT_EPSILON) static CGFloat const SVPullToRefreshViewHeight = 60; @interface SVPullToRefreshArrow : UIView @property (nonatomic, strong) UIColor *arrowColor; @end @interface SVPullToRefreshView () @property (nonatomic, copy) void (^pullToRefreshActionHandler)(void); @property (nonatomic, strong) SVPullToRefreshArrow *arrow; @property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView; @property (nonatomic, strong, readwrite) UILabel *titleLabel; @property (nonatomic, strong, readwrite) UILabel *subtitleLabel; @property (nonatomic, readwrite) SVPullToRefreshState state; @property (nonatomic, strong) NSMutableArray *titles; @property (nonatomic, strong) NSMutableArray *subtitles; @property (nonatomic, strong) NSMutableArray *viewForState; @property (nonatomic, weak) UIScrollView *scrollView; @property (nonatomic, readwrite) CGFloat originalTopInset; @property (nonatomic, assign) BOOL wasTriggeredByUser; @property (nonatomic, assign) BOOL showsPullToRefresh; @property (nonatomic, assign) BOOL showsDateLabel; @property(nonatomic, assign) BOOL isObserving; @property (nonatomic, assign) CGFloat pullOffset; - (void)resetScrollViewContentInset; - (void)setScrollViewContentInsetForLoading; - (void)setScrollViewContentInset:(UIEdgeInsets)insets; - (void)rotateArrow:(float)degrees hide:(BOOL)hide; @end #pragma mark - UIScrollView (SVPullToRefresh) #import <objc/runtime.h> static char UIScrollViewPullToRefreshView; @implementation UIScrollView (SVPullToRefresh) @dynamic pullToRefreshView, showsPullToRefresh; - (void)addPullToRefreshOffset:(CGFloat)offset withActionHandler:(void (^)(void))actionHandler { if(!self.pullToRefreshView) { SVPullToRefreshView *view = [[SVPullToRefreshView alloc] initWithFrame:CGRectMake(0, -SVPullToRefreshViewHeight, self.bounds.size.width, SVPullToRefreshViewHeight)]; view.pullToRefreshActionHandler = actionHandler; view.pullOffset = offset; view.scrollView = self; [self addSubview:view]; view.originalTopInset = self.contentInset.top + offset; self.pullToRefreshView = view; self.showsPullToRefresh = YES; } } - (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler { [self addPullToRefreshOffset:0 withActionHandler:actionHandler]; } - (void)triggerPullToRefresh { [self triggerPullToRefreshAnimated:YES]; } - (void)triggerPullToRefreshAnimated:(BOOL)animated{ self.pullToRefreshView.state = SVPullToRefreshStateTriggered; [self.pullToRefreshView startAnimating:animated]; } - (void)setPullToRefreshView:(SVPullToRefreshView *)pullToRefreshView { [self willChangeValueForKey:@"SVPullToRefreshView"]; objc_setAssociatedObject(self, &UIScrollViewPullToRefreshView, pullToRefreshView, OBJC_ASSOCIATION_ASSIGN); [self didChangeValueForKey:@"SVPullToRefreshView"]; } - (SVPullToRefreshView *)pullToRefreshView { return objc_getAssociatedObject(self, &UIScrollViewPullToRefreshView); } - (void)setShowsPullToRefresh:(BOOL)showsPullToRefresh { self.pullToRefreshView.hidden = !showsPullToRefresh; if(!showsPullToRefresh) { if (self.pullToRefreshView.isObserving) { [self removeObserver:self.pullToRefreshView forKeyPath:@"contentOffset"]; [self removeObserver:self.pullToRefreshView forKeyPath:@"frame"]; [self.pullToRefreshView resetScrollViewContentInset]; self.pullToRefreshView.isObserving = NO; } } else { if (!self.pullToRefreshView.isObserving) { [self addObserver:self.pullToRefreshView forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self.pullToRefreshView forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil]; self.pullToRefreshView.isObserving = YES; } } } - (BOOL)showsPullToRefresh { return !self.pullToRefreshView.hidden; } @end #pragma mark - SVPullToRefresh @implementation SVPullToRefreshView // public properties @synthesize pullToRefreshActionHandler, arrowColor, textColor, activityIndicatorViewStyle, lastUpdatedDate, dateFormatter; @synthesize state = _state; @synthesize scrollView = _scrollView; @synthesize showsPullToRefresh = _showsPullToRefresh; @synthesize arrow = _arrow; @synthesize activityIndicatorView = _activityIndicatorView; @synthesize titleLabel = _titleLabel; @synthesize dateLabel = _dateLabel; - (id)initWithFrame:(CGRect)frame { if(self = [super initWithFrame:frame]) { // default styling values self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; self.textColor = [UIColor darkGrayColor]; self.autoresizingMask = UIViewAutoresizingFlexibleWidth; self.state = SVPullToRefreshStateStopped; self.showsDateLabel = NO; self.titles = [NSMutableArray arrayWithObjects:NSLocalizedString(@"Pull to refresh...",), NSLocalizedString(@"Release to refresh...",), NSLocalizedString(@"Loading...",), nil]; self.subtitles = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", nil]; self.viewForState = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", nil]; } return self; } - (void)willMoveToSuperview:(UIView *)newSuperview { if (self.superview && newSuperview == nil) { //use self.superview, not self.scrollView. Why self.scrollView == nil here? UIScrollView *scrollView = (UIScrollView *)self.superview; if (scrollView.showsPullToRefresh) { if (self.isObserving) { //If enter this branch, it is the moment just before "SVPullToRefreshView's dealloc", so remove observer here [scrollView removeObserver:self forKeyPath:@"contentOffset"]; [scrollView removeObserver:self forKeyPath:@"frame"]; self.isObserving = NO; } } } } - (void)layoutSubviews { CGFloat remainingWidth = self.superview.bounds.size.width-200; float position = 0.50; CGRect titleFrame = self.titleLabel.frame; titleFrame.origin.x = ceilf(remainingWidth*position+44); titleFrame.origin.y = self.bounds.size.height-(self.subtitleLabel.text ? 48 : 40); self.titleLabel.frame = titleFrame; CGRect subtitleFrame = self.subtitleLabel.frame; subtitleFrame.origin.x = titleFrame.origin.x; subtitleFrame.origin.y = self.bounds.size.height-32; self.subtitleLabel.frame = subtitleFrame; CGRect arrowFrame = self.arrow.frame; arrowFrame.origin.x = ceilf(remainingWidth*position); self.arrow.frame = arrowFrame; self.activityIndicatorView.center = self.arrow.center; for(id otherView in self.viewForState) { if([otherView isKindOfClass:[UIView class]]) [otherView removeFromSuperview]; } id customView = [self.viewForState objectAtIndex:self.state]; BOOL hasCustomView = [customView isKindOfClass:[UIView class]]; self.titleLabel.hidden = hasCustomView; self.subtitleLabel.hidden = hasCustomView; self.arrow.hidden = hasCustomView; if(hasCustomView) { [self addSubview:customView]; CGRect viewBounds = [customView bounds]; CGPoint origin = CGPointMake(roundf((self.bounds.size.width-viewBounds.size.width)/2), roundf((self.bounds.size.height-viewBounds.size.height)/2)); [customView setFrame:CGRectMake(origin.x, origin.y, viewBounds.size.width, viewBounds.size.height)]; } else { self.titleLabel.text = [self.titles objectAtIndex:self.state]; NSString *subtitle = [self.subtitles objectAtIndex:self.state]; if(subtitle.length > 0) self.subtitleLabel.text = subtitle; switch (self.state) { case SVPullToRefreshStateStopped: self.arrow.alpha = 1; [self.activityIndicatorView stopAnimating]; [self rotateArrow:0 hide:NO]; break; case SVPullToRefreshStateTriggered: [self rotateArrow:(float)M_PI hide:NO]; break; case SVPullToRefreshStateLoading: [self.activityIndicatorView startAnimating]; [self rotateArrow:0 hide:YES]; break; } } } #pragma mark - Scroll View - (void)resetScrollViewContentInset { UIEdgeInsets currentInsets = self.scrollView.contentInset; currentInsets.top = self.originalTopInset; [self setScrollViewContentInset:currentInsets]; } - (void)setScrollViewContentInsetForLoading { CGFloat offset = MAX(self.scrollView.contentOffset.y * -1, 0); UIEdgeInsets currentInsets = self.scrollView.contentInset; currentInsets.top = MIN(offset, self.originalTopInset + self.bounds.size.height); [self setScrollViewContentInset:currentInsets]; } - (void)setScrollViewContentInset:(UIEdgeInsets)contentInset { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState animations:^{ self.scrollView.contentInset = contentInset; } completion:NULL]; } #pragma mark - Observing - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([keyPath isEqualToString:@"contentOffset"]) [self scrollViewDidScroll:[[change valueForKey:NSKeyValueChangeNewKey] CGPointValue]]; else if([keyPath isEqualToString:@"frame"]) [self layoutSubviews]; } - (void)scrollViewDidScroll:(CGPoint)contentOffset { if(self.state != SVPullToRefreshStateLoading) { CGFloat scrollOffsetThreshold = self.frame.origin.y-self.originalTopInset; if(!self.scrollView.isDragging && self.state == SVPullToRefreshStateTriggered) self.state = SVPullToRefreshStateLoading; else if(contentOffset.y < scrollOffsetThreshold && self.scrollView.isDragging && self.state == SVPullToRefreshStateStopped) self.state = SVPullToRefreshStateTriggered; else if(contentOffset.y >= scrollOffsetThreshold && self.state != SVPullToRefreshStateStopped) self.state = SVPullToRefreshStateStopped; } else { CGFloat offset = MAX(self.scrollView.contentOffset.y * -1, 0.0f); offset = MIN(offset, self.originalTopInset + self.bounds.size.height); UIEdgeInsets contentInset = self.scrollView.contentInset; self.scrollView.contentInset = UIEdgeInsetsMake(offset, contentInset.left, contentInset.bottom, contentInset.right); } } #pragma mark - Getters - (SVPullToRefreshArrow *)arrow { if(!_arrow) { _arrow = [[SVPullToRefreshArrow alloc]initWithFrame:CGRectMake(0, self.bounds.size.height-54, 22, 48)]; _arrow.backgroundColor = [UIColor clearColor]; [self addSubview:_arrow]; } return _arrow; } - (UIActivityIndicatorView *)activityIndicatorView { if(!_activityIndicatorView) { _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; _activityIndicatorView.hidesWhenStopped = YES; [self addSubview:_activityIndicatorView]; } return _activityIndicatorView; } - (UILabel *)titleLabel { if(!_titleLabel) { _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 210, 20)]; _titleLabel.text = NSLocalizedString(@"Pull to refresh...",); _titleLabel.font = [UIFont boldSystemFontOfSize:14]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textColor = textColor; [self addSubview:_titleLabel]; } return _titleLabel; } - (UILabel *)subtitleLabel { if(!_subtitleLabel) { _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 210, 20)]; _subtitleLabel.font = [UIFont systemFontOfSize:12]; _subtitleLabel.backgroundColor = [UIColor clearColor]; _subtitleLabel.textColor = textColor; [self addSubview:_subtitleLabel]; } return _subtitleLabel; } - (UILabel *)dateLabel { return self.showsDateLabel ? self.subtitleLabel : nil; } - (NSDateFormatter *)dateFormatter { if(!dateFormatter) { dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; dateFormatter.locale = [NSLocale currentLocale]; } return dateFormatter; } - (UIColor *)arrowColor { return self.arrow.arrowColor; // pass through } - (UIColor *)textColor { return self.titleLabel.textColor; } - (UIActivityIndicatorViewStyle)activityIndicatorViewStyle { return self.activityIndicatorView.activityIndicatorViewStyle; } #pragma mark - Setters - (void)setArrowColor:(UIColor *)newArrowColor { self.arrow.arrowColor = newArrowColor; // pass through [self.arrow setNeedsDisplay]; } - (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state { if(!title) title = @""; if(state == SVPullToRefreshStateAll) [self.titles replaceObjectsInRange:NSMakeRange(0, 3) withObjectsFromArray:@[title, title, title]]; else [self.titles replaceObjectAtIndex:state withObject:title]; [self setNeedsLayout]; } - (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state { if(!subtitle) subtitle = @""; if(state == SVPullToRefreshStateAll) [self.subtitles replaceObjectsInRange:NSMakeRange(0, 3) withObjectsFromArray:@[subtitle, subtitle, subtitle]]; else [self.subtitles replaceObjectAtIndex:state withObject:subtitle]; [self setNeedsLayout]; } - (void)setCustomView:(UIView *)view forState:(SVPullToRefreshState)state { id viewPlaceholder = view; if(!viewPlaceholder) viewPlaceholder = @""; if(state == SVPullToRefreshStateAll) [self.viewForState replaceObjectsInRange:NSMakeRange(0, 3) withObjectsFromArray:@[viewPlaceholder, viewPlaceholder, viewPlaceholder]]; else [self.viewForState replaceObjectAtIndex:state withObject:viewPlaceholder]; [self setNeedsLayout]; } - (void)setTextColor:(UIColor *)newTextColor { textColor = newTextColor; self.titleLabel.textColor = newTextColor; self.subtitleLabel.textColor = newTextColor; } - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)viewStyle { self.activityIndicatorView.activityIndicatorViewStyle = viewStyle; } - (void)setLastUpdatedDate:(NSDate *)newLastUpdatedDate { self.showsDateLabel = YES; self.dateLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Last Updated: %@",), newLastUpdatedDate?[self.dateFormatter stringFromDate:newLastUpdatedDate]:NSLocalizedString(@"Never",)]; } - (void)setDateFormatter:(NSDateFormatter *)newDateFormatter { dateFormatter = newDateFormatter; self.dateLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Last Updated: %@",), self.lastUpdatedDate?[newDateFormatter stringFromDate:self.lastUpdatedDate]:NSLocalizedString(@"Never",)]; } #pragma mark - - (void)triggerRefresh { [self.scrollView triggerPullToRefresh]; } - (void)startAnimating:(BOOL)animated { CGFloat offset = self.scrollView.contentOffset.y+self.pullOffset; if(fequalzero(offset)) { [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, -self.frame.size.height + self.scrollView.contentOffset.y) animated:animated]; self.wasTriggeredByUser = NO; } else{ self.wasTriggeredByUser = YES; } self.state = SVPullToRefreshStateLoading; } - (void)startAnimating{ [self startAnimating:YES]; } - (void)stopAnimating:(BOOL)animated { self.state = SVPullToRefreshStateStopped; if(!self.wasTriggeredByUser && self.scrollView.contentOffset.y < -self.originalTopInset) [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, -self.originalTopInset) animated:animated]; } - (void)stopAnimating { [self stopAnimating:YES]; } - (void)setState:(SVPullToRefreshState)newState { if(_state == newState) return; SVPullToRefreshState previousState = _state; _state = newState; [self setNeedsLayout]; switch (newState) { case SVPullToRefreshStateStopped: [self resetScrollViewContentInset]; break; case SVPullToRefreshStateTriggered: break; case SVPullToRefreshStateLoading: [self setScrollViewContentInsetForLoading]; if(previousState == SVPullToRefreshStateTriggered && pullToRefreshActionHandler) pullToRefreshActionHandler(); break; } } - (void)rotateArrow:(float)degrees hide:(BOOL)hide { [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.arrow.layer.transform = CATransform3DMakeRotation(degrees, 0, 0, 1); self.arrow.layer.opacity = !hide; //[self.arrow setNeedsDisplay];//ios 4 } completion:NULL]; } @end #pragma mark - SVPullToRefreshArrow @implementation SVPullToRefreshArrow @synthesize arrowColor; - (UIColor *)arrowColor { if (arrowColor) return arrowColor; return [UIColor grayColor]; // default Color } - (void)drawRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext(); // the rects above the arrow CGContextAddRect(c, CGRectMake(5, 0, 12, 4)); // to-do: use dynamic points CGContextAddRect(c, CGRectMake(5, 6, 12, 4)); // currently fixed size: 22 x 48pt CGContextAddRect(c, CGRectMake(5, 12, 12, 4)); CGContextAddRect(c, CGRectMake(5, 18, 12, 4)); CGContextAddRect(c, CGRectMake(5, 24, 12, 4)); CGContextAddRect(c, CGRectMake(5, 30, 12, 4)); // the arrow CGContextMoveToPoint(c, 0, 34); CGContextAddLineToPoint(c, 11, 48); CGContextAddLineToPoint(c, 22, 34); CGContextAddLineToPoint(c, 0, 34); CGContextClosePath(c); CGContextSaveGState(c); CGContextClip(c); // Gradient Declaration CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat alphaGradientLocations[] = {0, 0.8f}; CGGradientRef alphaGradient = nil; if([[[UIDevice currentDevice] systemVersion]floatValue] >= 5){ NSArray* alphaGradientColors = [NSArray arrayWithObjects: (id)[self.arrowColor colorWithAlphaComponent:0].CGColor, (id)[self.arrowColor colorWithAlphaComponent:1].CGColor, nil]; alphaGradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)alphaGradientColors, alphaGradientLocations); }else{ const CGFloat * components = CGColorGetComponents([self.arrowColor CGColor]); int numComponents = (int)CGColorGetNumberOfComponents([self.arrowColor CGColor]); CGFloat colors[8]; switch(numComponents){ case 2:{ colors[0] = colors[4] = components[0]; colors[1] = colors[5] = components[0]; colors[2] = colors[6] = components[0]; break; } case 4:{ colors[0] = colors[4] = components[0]; colors[1] = colors[5] = components[1]; colors[2] = colors[6] = components[2]; break; } } colors[3] = 0; colors[7] = 1; alphaGradient = CGGradientCreateWithColorComponents(colorSpace,colors,alphaGradientLocations,2); } CGContextDrawLinearGradient(c, alphaGradient, CGPointZero, CGPointMake(0, rect.size.height), 0); CGContextRestoreGState(c); CGGradientRelease(alphaGradient); CGColorSpaceRelease(colorSpace); } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SVPullToRefresh/UIScrollView+SVPullToRefresh.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
4,495
```objective-c // // SDTimeLineRefreshHeader.m // #import "SDTimeLineRefreshHeader.h" static const CGFloat criticalY = -60.f; #define kSDTimeLineRefreshHeaderRotateAnimationKey @"RotateAnimationKey" @implementation SDTimeLineRefreshHeader { CABasicAnimation *_rotateAnimation; } + (instancetype)refreshHeaderWithCenter:(CGPoint)center { SDTimeLineRefreshHeader *header = [SDTimeLineRefreshHeader new]; header.center = center; return header; } - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setupView]; } return self; } - (void)setupView { self.backgroundColor = [UIColor clearColor]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"AlbumReflashIcon"]]; self.bounds = imageView.bounds; [self addSubview:imageView]; _rotateAnimation = [[CABasicAnimation alloc] init]; _rotateAnimation.keyPath = @"transform.rotation.z"; _rotateAnimation.fromValue = @0; _rotateAnimation.toValue = @(M_PI * 2); _rotateAnimation.duration = 1.0; _rotateAnimation.repeatCount = MAXFLOAT; } - (void)setRefreshState:(SDWXRefreshViewState)refreshState { [super setRefreshState:refreshState]; if (refreshState == SDWXRefreshViewStateRefreshing) { if (self.refreshingBlock) { self.refreshingBlock(); } [self.layer addAnimation:_rotateAnimation forKey:kSDTimeLineRefreshHeaderRotateAnimationKey]; } else if (refreshState == SDWXRefreshViewStateNormal) { [self.layer removeAnimationForKey:kSDTimeLineRefreshHeaderRotateAnimationKey]; [UIView animateWithDuration:0.3 animations:^{ self.transform = CGAffineTransformIdentity; }]; } } - (void)updateRefreshHeaderWithOffsetY:(CGFloat)y { CGFloat rotateValue = y / 50.0 * M_PI; if (y < criticalY) { y = criticalY; if (self.scrollView.isDragging && self.refreshState != SDWXRefreshViewStateWillRefresh) { self.refreshState = SDWXRefreshViewStateWillRefresh; } else if (!self.scrollView.isDragging && self.refreshState == SDWXRefreshViewStateWillRefresh) { self.refreshState = SDWXRefreshViewStateRefreshing; } } if (self.refreshState == SDWXRefreshViewStateRefreshing) return; CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformTranslate(transform, 0, -y); transform = CGAffineTransformRotate(transform, rotateValue); self.transform = transform; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { if (keyPath != kSDBaseRefreshViewObserveKeyPath) return; [self updateRefreshHeaderWithOffsetY:self.scrollView.contentOffset.y]; } @end ```
/content/code_sandbox/BigShow1949/Classes/03 - ViewLayout(视图布局)/ArtPageView/SDRefresh/SDTimeLineRefreshHeader.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
639
```objective-c // // YFViewTransitionViewController.m // BigShow1949 // // Created by zhht01 on 16/3/17. // #import "YFViewTransitionViewController.h" @interface YFViewTransitionViewController () @end @implementation YFViewTransitionViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupDataArr:@[@[@"",@"YFBaiduViewTransitionViewController"], @[@"",@"RZSimpleViewController_UIStoryboard"], @[@"LTSlidingTransitions",@"YFSlidingViewController_UIStoryboard"], @[@"",@"YFFlipPageViewController"], @[@"",@"YFDraggableCardViewController"], @[@"",@"YFITRAirSideViewController"],]]; } @end ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/YFViewTransitionViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
153
```objective-c // // YFViewTransitionViewController.h // BigShow1949 // // Created by zhht01 on 16/3/17. // #import "BaseTableViewController.h" @interface YFViewTransitionViewController : BaseTableViewController @end ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/YFViewTransitionViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
55
```objective-c // // ITRSecondViewController.m // ITRAirSideMenu // // Created by kirthi on 12/08/15. // #import "ITRSecondViewController.h" #import "ITRAirSideMenu.h" #import "AppDelegate.h" @interface ITRSecondViewController () @end @implementation ITRSecondViewController + (instancetype) controller{ // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // return [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ITRSecondViewController class])]; ITRSecondViewController *secondVC = [[ITRSecondViewController alloc] init]; secondVC.view.backgroundColor = [UIColor yellowColor]; return secondVC; } #pragma view lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.navigationController.navigationBar.translucent = NO; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStylePlain target:self action:@selector(presentLeftMenuViewController)]; } - (void) presentLeftMenuViewController{ // //show left menu with animation // ITRAirSideMenu *itrSideMenu = ((AppDelegate *)[UIApplication sharedApplication].delegate).itrAirSideMenu; // [itrSideMenu presentLeftMenuViewController]; } @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/ITRAirSideMenu/ITRSecondViewController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
290
```objective-c // // ITRSecondViewController.h // ITRAirSideMenu // // Created by kirthi on 12/08/15. // #import <UIKit/UIKit.h> @interface ITRSecondViewController : UIViewController + (instancetype) controller; @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/ITRAirSideMenu/ITRSecondViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
78
```objective-c // // ViewController.h // ITRAirSideMenu // // Created by kirthi on 11/08/15. // #import <UIKit/UIKit.h> @interface ITRFirstViewController : UIViewController + (instancetype) controller; @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/ITRAirSideMenu/ITRFirstViewController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
75
```objective-c // // LeftMenuController.m // ITRAirSideMenu // // Created by kirthi on 12/08/15. // #import "ITRLeftMenuController.h" #import "ITRFirstViewController.h" #import "ITRSecondViewController.h" #import "AppDelegate.h" @interface ITRLeftMenuController () { NSIndexPath *selectedIndexPath; } //@property (weak, nonatomic) IBOutlet UITableView *tableView; @end @implementation ITRLeftMenuController + (instancetype)controller { // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // return [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ITRLeftMenuController class])]; ITRLeftMenuController *leftVC = [[ITRLeftMenuController alloc] init]; return leftVC; } #pragma view lifecycle - (void)viewDidLoad { [super viewDidLoad]; } #pragma mark - #pragma mark UITableView Delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // [tableView deselectRowAtIndexPath:indexPath animated:YES]; // // ITRAirSideMenu *itrSideMenu = ((AppDelegate *)[UIApplication sharedApplication].delegate).itrAirSideMenu; // //update content view controller with setContentViewController // [itrSideMenu hideMenuViewController]; // selectedIndexPath = indexPath; } #pragma mark - #pragma mark UITableView Datasource - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 54; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex { return 5; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.backgroundColor = [UIColor clearColor]; cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21]; cell.textLabel.textColor = [UIColor whiteColor]; cell.textLabel.highlightedTextColor = [UIColor lightGrayColor]; cell.selectedBackgroundView = [[UIView alloc] init]; } NSArray *titles = @[@"Menu1", @"Menu2", @"Menu3", @"Menu4", @"Menu5"]; cell.textLabel.text = titles[indexPath.row]; return cell; } #pragma mark - #pragma mark ITRAirSideMenu Delegate - (void)sideMenu:(ITRAirSideMenu *)sideMenu didRecognizePanGesture:(UIPanGestureRecognizer *)recognizer { NSLog(@"didRecognizePanGesture"); } - (void)sideMenu:(ITRAirSideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController { NSLog(@"willShowMenuViewController: %@ isMenuVisible <%d>", NSStringFromClass([menuViewController class]), (int)sideMenu.isLeftMenuVisible ); } - (void)sideMenu:(ITRAirSideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController { NSLog(@"didShowMenuViewController: %@ isMenuVisible <%d>", NSStringFromClass([menuViewController class]), (int)sideMenu.isLeftMenuVisible ); } - (void)sideMenu:(ITRAirSideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController { NSLog(@"willHideMenuViewController: %@ isMenuVisible <%d>", NSStringFromClass([menuViewController class]), (int)sideMenu.isLeftMenuVisible ); } - (void)sideMenu:(ITRAirSideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController{ NSLog(@"didHideMenuViewController: %@ isMenuVisible <%d>", NSStringFromClass([menuViewController class]), (int)sideMenu.isLeftMenuVisible ); if (selectedIndexPath.row % 2 == 0) { [sideMenu setContentViewController:[[UINavigationController alloc] initWithRootViewController:[ITRFirstViewController controller]]]; }else{ [sideMenu setContentViewController:[[UINavigationController alloc] initWithRootViewController:[ITRSecondViewController controller]]]; } } @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/ITRAirSideMenu/ITRLeftMenuController.m
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
889
```objective-c // // LeftMenuController.h // ITRAirSideMenu // // Created by kirthi on 12/08/15. // #import <UIKit/UIKit.h> #import "ITRAirSideMenu.h" @interface ITRLeftMenuController : UIViewController<UITableViewDataSource, UITableViewDelegate, ITRAirSideMenuDelegate> + (instancetype) controller; @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/ITRAirSideMenu/ITRLeftMenuController.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
99
```objective-c #import <UIKit/UIKit.h> @protocol ITRAirSideMenuDelegate; @interface ITRAirSideMenu : UIViewController <UIGestureRecognizerDelegate> @property (strong, readwrite, nonatomic) UIViewController *contentViewController; @property (strong, readwrite, nonatomic) UIViewController *leftMenuViewController; @property (weak, readwrite, nonatomic) id<ITRAirSideMenuDelegate> delegate; @property (assign, readonly, nonatomic, getter=isLeftMenuVisible) BOOL isLeftMenuVisible; @property (assign, readwrite, nonatomic) NSTimeInterval animationDuration; @property (strong, readwrite, nonatomic) UIImage *backgroundImage; @property (assign, readwrite, nonatomic) BOOL panGestureEnabled; @property (assign, readwrite, nonatomic) BOOL panFromEdge; @property (assign, readwrite, nonatomic) NSUInteger panMinimumOpenThreshold; @property (assign, readwrite, nonatomic) IBInspectable BOOL interactivePopGestureRecognizerEnabled; @property (assign, readwrite, nonatomic) IBInspectable BOOL contentViewShadowEnabled; @property (strong, readwrite, nonatomic) IBInspectable UIColor *contentViewShadowColor; @property (assign, readwrite, nonatomic) IBInspectable CGSize contentViewShadowOffset; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewShadowOpacity; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewShadowRadius; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewFadeOutAlpha; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewScaleValue; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewRotatingAngle; @property (assign, readwrite, nonatomic) IBInspectable CGFloat contentViewTranslateX; @property (assign, readwrite, nonatomic) IBInspectable CGFloat menuViewRotatingAngle; @property (assign, readwrite, nonatomic) IBInspectable CGFloat menuViewTranslateX; - (id)initWithContentViewController:(UIViewController *)contentViewController leftMenuViewController:(UIViewController *)leftMenuViewController; - (void)presentLeftMenuViewController; - (void)hideMenuViewController; - (void)setContentViewController:(UIViewController *)contentViewController animated:(BOOL)animated; @end @protocol ITRAirSideMenuDelegate <NSObject> @optional - (void)sideMenu:(ITRAirSideMenu *)sideMenu didRecognizePanGesture:(UIPanGestureRecognizer *)recognizer; - (void)sideMenu:(ITRAirSideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController; - (void)sideMenu:(ITRAirSideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController; - (void)sideMenu:(ITRAirSideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController; - (void)sideMenu:(ITRAirSideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController; @end // // path_to_url (cn) path_to_url (en) // : Code4App.com ```
/content/code_sandbox/BigShow1949/Classes/04 - ViewTransition(视图切换)/ITRAirSideMenu/ITRAirSideMenu.h
objective-c
2016-05-05T08:19:43
2024-08-07T09:29:21
BigShow1949
BigShow1949/BigShow1949
1,121
592