From a4891b63002a8a38018812fbf44986a65c893944 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 18 Nov 2014 14:37:32 +0800 Subject: [PATCH] Add Demo use for UINavigationController. --- .../AFSwipeToHide.xcodeproj/project.pbxproj | 36 +++++++++-- .../AFSwipeToHide/AFRootTableViewController.h | 13 ++++ .../AFSwipeToHide/AFRootTableViewController.m | 64 +++++++++++++++++++ Example/AFSwipeToHide/ControllerNameItem.h | 23 +++++++ Example/AFSwipeToHide/ControllerNameItem.m | 34 ++++++++++ Example/AFSwipeToHide/Main.storyboard | 60 +++++++++++++++-- Example/AFSwipeToHide/ViewController.h | 4 ++ Example/AFSwipeToHide/ViewController.m | 31 ++++++++- 8 files changed, 255 insertions(+), 10 deletions(-) create mode 100644 Example/AFSwipeToHide/AFRootTableViewController.h create mode 100644 Example/AFSwipeToHide/AFRootTableViewController.m create mode 100644 Example/AFSwipeToHide/ControllerNameItem.h create mode 100644 Example/AFSwipeToHide/ControllerNameItem.m diff --git a/Example/AFSwipeToHide.xcodeproj/project.pbxproj b/Example/AFSwipeToHide.xcodeproj/project.pbxproj index 99ca4af..ccf6336 100644 --- a/Example/AFSwipeToHide.xcodeproj/project.pbxproj +++ b/Example/AFSwipeToHide.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; }; 6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; }; + 7DDF9C801A1B1B2E00FF236C /* AFRootTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DDF9C7F1A1B1B2E00FF236C /* AFRootTableViewController.m */; }; + 7DDF9C831A1B1DA600FF236C /* ControllerNameItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DDF9C821A1B1DA600FF236C /* ControllerNameItem.m */; }; A3793E1B418B251CF9E9D323 /* libPods-AFSwipeToHide.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BC87DD27DA7BB70B8EEEF35 /* libPods-AFSwipeToHide.a */; }; DA8EB0F30EA401214E37EBE7 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 330B05E7436C539DC56B70F8 /* libPods-Tests.a */; }; /* End PBXBuildFile section */ @@ -62,6 +64,10 @@ 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; }; 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; + 7DDF9C7E1A1B1B2E00FF236C /* AFRootTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFRootTableViewController.h; sourceTree = ""; }; + 7DDF9C7F1A1B1B2E00FF236C /* AFRootTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFRootTableViewController.m; sourceTree = ""; }; + 7DDF9C811A1B1DA600FF236C /* ControllerNameItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControllerNameItem.h; sourceTree = ""; }; + 7DDF9C821A1B1DA600FF236C /* ControllerNameItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ControllerNameItem.m; sourceTree = ""; }; 8F62D1C4AC0681D0E23FE8A1 /* Pods-AFSwipeToHide.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AFSwipeToHide.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AFSwipeToHide/Pods-AFSwipeToHide.debug.xcconfig"; sourceTree = ""; }; E42E6FCAC9046D95FBFC5D69 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; FB807404A9E3A47C20E6D937 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; @@ -132,8 +138,8 @@ children = ( 2D15B2971A02CE6000DE511E /* AppDelegate.h */, 2D15B2981A02CE6000DE511E /* AppDelegate.m */, - 2D15B2991A02CE6000DE511E /* ViewController.h */, - 2D15B29A1A02CE6000DE511E /* ViewController.m */, + 7DDF9C841A1B1E1800FF236C /* UIModel */, + 7DDF9C851A1B1E2200FF236C /* Controllers */, 2D15B29D1A02CEA600DE511E /* Main.storyboard */, 6003F5A8195388D20070C39A /* Images.xcassets */, 6003F594195388D20070C39A /* Supporting Files */, @@ -192,6 +198,26 @@ name = Pods; sourceTree = ""; }; + 7DDF9C841A1B1E1800FF236C /* UIModel */ = { + isa = PBXGroup; + children = ( + 7DDF9C811A1B1DA600FF236C /* ControllerNameItem.h */, + 7DDF9C821A1B1DA600FF236C /* ControllerNameItem.m */, + ); + name = UIModel; + sourceTree = ""; + }; + 7DDF9C851A1B1E2200FF236C /* Controllers */ = { + isa = PBXGroup; + children = ( + 7DDF9C7E1A1B1B2E00FF236C /* AFRootTableViewController.h */, + 7DDF9C7F1A1B1B2E00FF236C /* AFRootTableViewController.m */, + 2D15B2991A02CE6000DE511E /* ViewController.h */, + 2D15B29A1A02CE6000DE511E /* ViewController.m */, + ); + name = Controllers; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -357,9 +383,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7DDF9C801A1B1B2E00FF236C /* AFRootTableViewController.m in Sources */, 2D15B29B1A02CE6000DE511E /* AppDelegate.m in Sources */, 6003F59A195388D20070C39A /* main.m in Sources */, 2D15B29C1A02CE6000DE511E /* ViewController.m in Sources */, + 7DDF9C831A1B1DA600FF236C /* ControllerNameItem.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -482,7 +510,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "AFSwipeToHide/AFSwipeToHide-Prefix.pch"; INFOPLIST_FILE = "AFSwipeToHide/AFSwipeToHide-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -497,7 +525,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "AFSwipeToHide/AFSwipeToHide-Prefix.pch"; INFOPLIST_FILE = "AFSwipeToHide/AFSwipeToHide-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/Example/AFSwipeToHide/AFRootTableViewController.h b/Example/AFSwipeToHide/AFRootTableViewController.h new file mode 100644 index 0000000..adc5612 --- /dev/null +++ b/Example/AFSwipeToHide/AFRootTableViewController.h @@ -0,0 +1,13 @@ +// +// AFRootTableViewController.h +// AFSwipeToHide +// +// Created by dw_iOS iOS软件工程师 曾宪华 QQ:543413507 on 14-11-18. +// Copyright (c) 2014年 Oz. All rights reserved. +// + +#import + +@interface AFRootTableViewController : UITableViewController + +@end diff --git a/Example/AFSwipeToHide/AFRootTableViewController.m b/Example/AFSwipeToHide/AFRootTableViewController.m new file mode 100644 index 0000000..c804057 --- /dev/null +++ b/Example/AFSwipeToHide/AFRootTableViewController.m @@ -0,0 +1,64 @@ +// +// AFRootTableViewController.m +// AFSwipeToHide +// +// Created by dw_iOS iOS软件工程师 曾宪华 QQ:543413507 on 14-11-18. +// Copyright (c) 2014年 Oz. All rights reserved. +// + +#import "AFRootTableViewController.h" +#import "ViewController.h" +#import "ControllerNameItem.h" + +@interface AFRootTableViewController () + +@property (nonatomic, strong) NSMutableArray *dataSource; + +@end + +@implementation AFRootTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + self.title = @"AFSwipeToHide"; + + self.dataSource = [[ControllerNameItem newDataSource] mutableCopy]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + // Return the number of sections. + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + // Return the number of rows in the section. + return self.dataSource.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath]; + + // Configure the cell... + ControllerNameItem *item = self.dataSource[indexPath.row]; + cell.textLabel.text = item.title; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + ViewController *viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController"]; + if (viewController) { + viewController.item = self.dataSource[indexPath.row]; + [self.navigationController pushViewController:viewController animated:YES]; + } +} + +@end diff --git a/Example/AFSwipeToHide/ControllerNameItem.h b/Example/AFSwipeToHide/ControllerNameItem.h new file mode 100644 index 0000000..bac6553 --- /dev/null +++ b/Example/AFSwipeToHide/ControllerNameItem.h @@ -0,0 +1,23 @@ +// +// ControllerNameItem.h +// AFSwipeToHide +// +// Created by dw_iOS iOS软件工程师 曾宪华 QQ:543413507 on 14-11-18. +// Copyright (c) 2014年 Oz. All rights reserved. +// + +#import + +@interface ControllerNameItem : NSObject + +@property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSString *className; + +// Default is no +@property (nonatomic, assign) BOOL hasNavigationBar; + +- (instancetype)initWithTitle:(NSString *)title; + ++ (NSArray *)newDataSource; + +@end diff --git a/Example/AFSwipeToHide/ControllerNameItem.m b/Example/AFSwipeToHide/ControllerNameItem.m new file mode 100644 index 0000000..ea9a2e0 --- /dev/null +++ b/Example/AFSwipeToHide/ControllerNameItem.m @@ -0,0 +1,34 @@ +// +// ControllerNameItem.m +// AFSwipeToHide +// +// Created by dw_iOS iOS软件工程师 曾宪华 QQ:543413507 on 14-11-18. +// Copyright (c) 2014年 Oz. All rights reserved. +// + +#import "ControllerNameItem.h" + +@implementation ControllerNameItem + +- (instancetype)initWithTitle:(NSString *)title { + self = [super init]; + if (self) { + self.title = title; + } + return self; +} + ++ (NSArray *)newDataSource { + NSMutableArray *newDataSource = [[NSMutableArray alloc] init]; + + ControllerNameItem *item = [[ControllerNameItem alloc] initWithTitle:@"No Navigation Bar"]; + [newDataSource addObject:item]; + + item = [[ControllerNameItem alloc] initWithTitle:@"Has Navigation Bar"]; + item.hasNavigationBar = YES; + [newDataSource addObject:item]; + + return newDataSource; +} + +@end diff --git a/Example/AFSwipeToHide/Main.storyboard b/Example/AFSwipeToHide/Main.storyboard index 0c95f52..3ccf8e9 100644 --- a/Example/AFSwipeToHide/Main.storyboard +++ b/Example/AFSwipeToHide/Main.storyboard @@ -1,14 +1,15 @@ - + - + + - + @@ -45,6 +46,12 @@ + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/AFSwipeToHide/ViewController.h b/Example/AFSwipeToHide/ViewController.h index a1b8a6d..f2c37eb 100644 --- a/Example/AFSwipeToHide/ViewController.h +++ b/Example/AFSwipeToHide/ViewController.h @@ -20,7 +20,11 @@ #import +@class ControllerNameItem; + @interface ViewController : UIViewController +@property (nonatomic, strong) ControllerNameItem *item; + @end diff --git a/Example/AFSwipeToHide/ViewController.m b/Example/AFSwipeToHide/ViewController.m index 40791d3..e647c8e 100644 --- a/Example/AFSwipeToHide/ViewController.m +++ b/Example/AFSwipeToHide/ViewController.m @@ -20,6 +20,7 @@ #import "ViewController.h" #import +#import "ControllerNameItem.h" @interface ViewController () { @@ -37,9 +38,33 @@ @interface ViewController () @implementation ViewController +#pragma mark - Action + +- (IBAction)af_popToViewController:(UIBarButtonItem *)sender { + [self.navigationController popViewControllerAnimated:YES]; +} + +#pragma nark - Life Cycle + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + if (!self.item.hasNavigationBar) { + self.navigationController.navigationBarHidden = YES; + } +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + if (self.item.hasNavigationBar) { + self.navigationController.navigationBarHidden = NO; + } +} + - (void)viewDidLoad { [super viewDidLoad]; + self.edgesForExtendedLayout = UIRectEdgeNone; + _headerHeight = self.titleHeight.constant; _swipeToHide = [[AFSwipeToHide alloc] init]; @@ -56,6 +81,8 @@ - (void)viewDidLoad { self.tableView.delegate = (id)_swipeToHide; [self updateElements]; + + } - (void)updateElements { @@ -70,7 +97,7 @@ - (void)updateElements { #pragma mark - Sizing utils - (CGFloat)statusBarHeight { - return [[UIApplication sharedApplication] statusBarFrame].size.height; + return (self.item.hasNavigationBar ? 0 : [[UIApplication sharedApplication] statusBarFrame].size.height); } #pragma mark - AFUSwipeToHide delegate @@ -79,7 +106,7 @@ - (void)swipeToHide:(AFSwipeToHide *)swipeToHide didUpdatePercentHiddenInteracti [self updateElements]; if (!interactive) { - [UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.45 initialSpringVelocity:0.0 options:0 animations:^{ + [UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.65 initialSpringVelocity:0.0 options:0 animations:^{ [self.view setNeedsLayout]; [self.view layoutIfNeeded]; } completion:nil];