| /* |
| Copyright 2016-present the Material Components for iOS authors. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| |
| #import <UIKit/UIKit.h> |
| |
| #import "MaterialAppBar.h" |
| |
| // This example builds upon AppBarTypicalUseExample. |
| |
| @interface AppBarDelegateForwardingExample : UITableViewController |
| @property(nonatomic, strong) MDCAppBar *appBar; |
| @end |
| |
| @implementation AppBarDelegateForwardingExample |
| |
| - (void)viewDidLoad { |
| [super viewDidLoad]; |
| |
| // UITableViewController's tableView.delegate is self by default. We're setting it here for |
| // emphasis. |
| self.tableView.delegate = self; |
| |
| self.appBar.headerViewController.headerView.trackingScrollView = self.tableView; |
| [self.appBar addSubviewsToParent]; |
| |
| self.tableView.layoutMargins = UIEdgeInsetsZero; |
| self.tableView.separatorInset = UIEdgeInsetsZero; |
| } |
| |
| #pragma mark - UIScrollViewDelegate |
| |
| // The following four methods must be forwarded to the tracking scroll view in order to implement |
| // the Flexible Header's behavior. |
| |
| - (void)scrollViewDidScroll:(UIScrollView *)scrollView { |
| if (scrollView == self.appBar.headerViewController.headerView.trackingScrollView) { |
| [self.appBar.headerViewController.headerView trackingScrollViewDidScroll]; |
| } |
| } |
| |
| - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { |
| if (scrollView == self.appBar.headerViewController.headerView.trackingScrollView) { |
| [self.appBar.headerViewController.headerView trackingScrollViewDidEndDecelerating]; |
| } |
| } |
| |
| - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { |
| MDCFlexibleHeaderView *headerView = self.appBar.headerViewController.headerView; |
| if (scrollView == headerView.trackingScrollView) { |
| [headerView trackingScrollViewDidEndDraggingWillDecelerate:decelerate]; |
| } |
| } |
| |
| - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView |
| withVelocity:(CGPoint)velocity |
| targetContentOffset:(inout CGPoint *)targetContentOffset { |
| MDCFlexibleHeaderView *headerView = self.appBar.headerViewController.headerView; |
| if (scrollView == headerView.trackingScrollView) { |
| [headerView trackingScrollViewWillEndDraggingWithVelocity:velocity |
| targetContentOffset:targetContentOffset]; |
| } |
| } |
| |
| @end |
| |
| @implementation AppBarDelegateForwardingExample (CatalogByConvention) |
| |
| + (NSArray *)catalogBreadcrumbs { |
| return @[ @"App Bar", @"Delegate Forwarding" ]; |
| } |
| |
| + (BOOL)catalogIsPrimaryDemo { |
| return NO; |
| } |
| |
| - (BOOL)catalogShouldHideNavigation { |
| return YES; |
| } |
| |
| @end |
| |
| @implementation AppBarDelegateForwardingExample (TypicalUse) |
| |
| - (id)init { |
| self = [super init]; |
| if (self) { |
| _appBar = [[MDCAppBar alloc] init]; |
| [self addChildViewController:_appBar.headerViewController]; |
| |
| self.title = @"Delegate Forwarding"; |
| |
| UIColor *color = [UIColor colorWithWhite:0.2 alpha:1]; |
| _appBar.headerViewController.headerView.backgroundColor = color; |
| MDCAppBarTextColorAccessibilityMutator *mutator = |
| [[MDCAppBarTextColorAccessibilityMutator alloc] init]; |
| [mutator mutate:_appBar]; |
| } |
| return self; |
| } |
| |
| - (UIViewController *)childViewControllerForStatusBarHidden { |
| return self.appBar.headerViewController; |
| } |
| |
| - (UIViewController *)childViewControllerForStatusBarStyle { |
| return self.appBar.headerViewController; |
| } |
| |
| - (void)viewWillAppear:(BOOL)animated { |
| [super viewWillAppear:animated]; |
| |
| [self.navigationController setNavigationBarHidden:YES animated:animated]; |
| } |
| |
| @end |
| |
| #pragma mark - Typical application code (not Material-specific) |
| |
| @implementation AppBarDelegateForwardingExample (UITableViewDataSource) |
| |
| - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
| return 50; |
| } |
| |
| - (UITableViewCell *)tableView:(UITableView *)tableView |
| cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
| UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"]; |
| if (!cell) { |
| cell = |
| [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; |
| } |
| cell.layoutMargins = UIEdgeInsetsZero; |
| return cell; |
| } |
| |
| @end |