Skip to content

Commit

Permalink
Fix bug and add no swipable header example. FIXED: akiroom#10
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroki Akiyama committed Jun 13, 2014
1 parent c15ed76 commit a7f4680
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 44 deletions.
2 changes: 1 addition & 1 deletion AXStretchableHeaderTabViewController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AXStretchableHeaderTabViewController"
s.version = "0.1.7"
s.version = "0.1.8"
s.summary = "Stretchable header view + Horizontal swipable tab view."
s.description = <<-DESC
Stretchable header view + Horizontal swipable tab view
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# AXStretchableHeaderTabViewController CHANGELOG

## 0.1.8

Feature: No swipable header is default. Look at "No horizontal swipe header" example.

## 0.1.7

Feature: Support "self" in interactive header view.
Expand Down
10 changes: 7 additions & 3 deletions Classes/AXStretchableHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
UIView *targetView = [super hitTest:point withEvent:event];
if (!targetView) {
return nil;
} else if (targetView == self) {
return nil;
}

NSArray *interactiveSubviews = [self.delegate interactiveSubviewsInStretchableHeaderView:self];
NSArray *interactiveSubviews;
if ([self.delegate respondsToSelector:@selector(interactiveSubviewsInStretchableHeaderView:)]) {
interactiveSubviews = [self.delegate interactiveSubviewsInStretchableHeaderView:self];
} else {
return targetView;
}

if ([interactiveSubviews containsObject:self]) {
return targetView;
}
Expand Down
60 changes: 50 additions & 10 deletions Example/StretchableHeaderTabViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
754814FA19323CC800CFD342 /* AXSampleTabViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 754814F819323CC800CFD342 /* AXSampleTabViewController.m */; };
75481502193241A800CFD342 /* sample-photo.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 75481501193241A800CFD342 /* sample-photo.jpg */; };
757BA7B219338CC3006ADDAF /* AXSampleNavBarTabViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 757BA7B119338CC3006ADDAF /* AXSampleNavBarTabViewController.m */; };
759D088E1935BEEB00E930BD /* AXSampleHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 759D088D1935BEEB00E930BD /* AXSampleHeaderView.m */; };
75A68DEB1935CBFD00C753FF /* AXSampleHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 75A68DEA1935CBFD00C753FF /* AXSampleHeaderView.xib */; };
7584B665194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7584B664194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.m */; };
7584B667194A86ED00AEE4DF /* AXSampleNoSwipableHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7584B666194A86ED00AEE4DF /* AXSampleNoSwipableHeaderView.xib */; };
7584B66A194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7584B669194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.m */; };
759D088E1935BEEB00E930BD /* AXSampleSwipableHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 759D088D1935BEEB00E930BD /* AXSampleSwipableHeaderView.m */; };
75A68DEB1935CBFD00C753FF /* AXSampleSwipableHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 75A68DEA1935CBFD00C753FF /* AXSampleSwipableHeaderView.xib */; };
7777FECBD35D45B6935E3121 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 77E2F7A94B9542CEA1F1CC2F /* libPods.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -80,9 +83,14 @@
75481501193241A800CFD342 /* sample-photo.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "sample-photo.jpg"; sourceTree = "<group>"; };
757BA7B019338CC3006ADDAF /* AXSampleNavBarTabViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AXSampleNavBarTabViewController.h; sourceTree = "<group>"; };
757BA7B119338CC3006ADDAF /* AXSampleNavBarTabViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AXSampleNavBarTabViewController.m; sourceTree = "<group>"; };
759D088C1935BEEB00E930BD /* AXSampleHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AXSampleHeaderView.h; sourceTree = "<group>"; };
759D088D1935BEEB00E930BD /* AXSampleHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AXSampleHeaderView.m; sourceTree = "<group>"; };
75A68DEA1935CBFD00C753FF /* AXSampleHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AXSampleHeaderView.xib; sourceTree = "<group>"; };
7584B663194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AXSampleNoSwipableHeaderView.h; sourceTree = "<group>"; };
7584B664194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AXSampleNoSwipableHeaderView.m; sourceTree = "<group>"; };
7584B666194A86ED00AEE4DF /* AXSampleNoSwipableHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AXSampleNoSwipableHeaderView.xib; sourceTree = "<group>"; };
7584B668194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AXSampleNoSwipableTabViewController.h; sourceTree = "<group>"; };
7584B669194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AXSampleNoSwipableTabViewController.m; sourceTree = "<group>"; };
759D088C1935BEEB00E930BD /* AXSampleSwipableHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AXSampleSwipableHeaderView.h; sourceTree = "<group>"; };
759D088D1935BEEB00E930BD /* AXSampleSwipableHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AXSampleSwipableHeaderView.m; sourceTree = "<group>"; };
75A68DEA1935CBFD00C753FF /* AXSampleSwipableHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AXSampleSwipableHeaderView.xib; sourceTree = "<group>"; };
77E2F7A94B9542CEA1F1CC2F /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
CDE287AB09714778AADFE7FE /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -160,9 +168,8 @@
75101E7519370B3E00AE76E8 /* Header View */ = {
isa = PBXGroup;
children = (
759D088C1935BEEB00E930BD /* AXSampleHeaderView.h */,
759D088D1935BEEB00E930BD /* AXSampleHeaderView.m */,
75A68DEA1935CBFD00C753FF /* AXSampleHeaderView.xib */,
7584B661194A85D800AEE4DF /* Swipable header view */,
7584B660194A85C800AEE4DF /* No swipe header view */,
);
name = "Header View";
sourceTree = "<group>";
Expand Down Expand Up @@ -272,12 +279,42 @@
754814DD19323A9400CFD342 /* Sub View Controllers */,
75101E7319370B0400AE76E8 /* TabVC (no bounce) */,
75101E7419370B1000AE76E8 /* TabVC (no header) */,
7584B662194A869D00AEE4DF /* TabVC (no swipe) */,
75101E7119370ADC00AE76E8 /* TabVC (with Nav Bar) */,
75101E7219370AF000AE76E8 /* TabVC (without Nav Bar) */,
);
name = "Sample Tab View Controller";
sourceTree = "<group>";
};
7584B660194A85C800AEE4DF /* No swipe header view */ = {
isa = PBXGroup;
children = (
7584B663194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.h */,
7584B664194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.m */,
7584B666194A86ED00AEE4DF /* AXSampleNoSwipableHeaderView.xib */,
);
name = "No swipe header view";
sourceTree = "<group>";
};
7584B661194A85D800AEE4DF /* Swipable header view */ = {
isa = PBXGroup;
children = (
759D088C1935BEEB00E930BD /* AXSampleSwipableHeaderView.h */,
759D088D1935BEEB00E930BD /* AXSampleSwipableHeaderView.m */,
75A68DEA1935CBFD00C753FF /* AXSampleSwipableHeaderView.xib */,
);
name = "Swipable header view";
sourceTree = "<group>";
};
7584B662194A869D00AEE4DF /* TabVC (no swipe) */ = {
isa = PBXGroup;
children = (
7584B668194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.h */,
7584B669194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.m */,
);
name = "TabVC (no swipe)";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -356,9 +393,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7584B667194A86ED00AEE4DF /* AXSampleNoSwipableHeaderView.xib in Resources */,
75481502193241A800CFD342 /* sample-photo.jpg in Resources */,
754814A9193234F400CFD342 /* InfoPlist.strings in Resources */,
75A68DEB1935CBFD00C753FF /* AXSampleHeaderView.xib in Resources */,
75A68DEB1935CBFD00C753FF /* AXSampleSwipableHeaderView.xib in Resources */,
754814B1193234F400CFD342 /* Images.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -414,13 +452,15 @@
75101E141935F7C500AE76E8 /* AXSampleNoBounceTabViewController.m in Sources */,
754814AB193234F400CFD342 /* main.m in Sources */,
754814E319323ABF00CFD342 /* AXSub2TableViewController.m in Sources */,
759D088E1935BEEB00E930BD /* AXSampleHeaderView.m in Sources */,
759D088E1935BEEB00E930BD /* AXSampleSwipableHeaderView.m in Sources */,
754814FA19323CC800CFD342 /* AXSampleTabViewController.m in Sources */,
75101E6E19370AC100AE76E8 /* AXEmptyViewController.m in Sources */,
754814E019323AA400CFD342 /* AXSub1TableViewController.m in Sources */,
757BA7B219338CC3006ADDAF /* AXSampleNavBarTabViewController.m in Sources */,
754814AF193234F400CFD342 /* AXAppDelegate.m in Sources */,
754814E619323ADF00CFD342 /* AXSub3ViewController.m in Sources */,
7584B665194A86C900AEE4DF /* AXSampleNoSwipableHeaderView.m in Sources */,
7584B66A194A875F00AEE4DF /* AXSampleNoSwipableTabViewController.m in Sources */,
75101E5E1936CE0F00AE76E8 /* AXSampleNoHeaderTabViewController.m in Sources */,
754814DC1932394E00CFD342 /* AXSampleListViewController.m in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
#import "AXSampleNavBarTabViewController.h"
#import "AXSampleNoBounceTabViewController.h"
#import "AXSampleNoHeaderTabViewController.h"
#import "AXSampleNoSwipableTabViewController.h"

@interface AXSampleListViewController ()

@end

@implementation AXSampleListViewController
@implementation AXSampleListViewController {
NSArray *_cellTitles;
}

- (id)initWithStyle:(UITableViewStyle)style
{
Expand All @@ -29,6 +32,14 @@ - (void)viewDidLoad
[super viewDidLoad];
[self setTitle:@"Stretchable header tab view"];

_cellTitles =
@[@"Sample",
@"No NavigationBar",
@"No bounce",
@"No header",
@"No horizontal swipe header",
];

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"list-cell"];
}

Expand All @@ -47,19 +58,14 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
return _cellTitles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"list-cell" forIndexPath:indexPath];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
[cell.textLabel setText:
@[@"Sample",
@"Sample with no NavigationBar",
@"Sample with no bounce",
@"Sample with no header view",
][indexPath.row]];
[cell.textLabel setText:_cellTitles[indexPath.row]];
return cell;
}

Expand Down Expand Up @@ -88,6 +94,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self.navigationController pushViewController:tabViewCon animated:YES];
break;
}
case 4: {
AXSampleNoSwipableTabViewController *tabViewCon = [[AXSampleNoSwipableTabViewController alloc] init];
[self.navigationController pushViewController:tabViewCon animated:YES];
break;
}
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import "AXSub1TableViewController.h"
#import "AXSub2TableViewController.h"
#import "AXSub3ViewController.h"
#import "AXSampleHeaderView.h"
#import "AXSampleSwipableHeaderView.h"

@interface AXSampleNavBarTabViewController ()

Expand All @@ -21,7 +21,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
if (self) {
self.title = @"Sample";

AXSampleHeaderView *headerView = [[AXSampleHeaderView alloc] init];
AXSampleSwipableHeaderView *headerView = [[AXSampleSwipableHeaderView alloc] init];
self.headerView = headerView;

AXSub1TableViewController *sub1ViewCon = [[AXSub1TableViewController alloc] init];
Expand All @@ -41,7 +41,7 @@ - (void)viewDidLoad
self.headerView.minimumOfHeight = 64.0;
self.headerView.maximumOfHeight = 220.0;

AXSampleHeaderView *headerView = (id)self.headerView;
AXSampleSwipableHeaderView *headerView = (id)self.headerView;
headerView.textLabel.text = @"The Duomo in Firenze";
headerView.imageView.image = [UIImage imageNamed:@"sample-photo.jpg"];
[headerView.backButton setTitle:@"back" forState:UIControlStateNormal];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#import "AXSampleNoBounceTabViewController.h"
#import "AXSub1TableViewController.h"
#import "AXSub2TableViewController.h"
#import "AXSampleHeaderView.h"
#import "AXSampleSwipableHeaderView.h"

@interface AXSampleNoBounceTabViewController ()

Expand All @@ -20,7 +20,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
if (self) {
self.title = @"No Bounce";

AXSampleHeaderView *headerView = [[AXSampleHeaderView alloc] init];
AXSampleSwipableHeaderView *headerView = [[AXSampleSwipableHeaderView alloc] init];

// THIS IS THE POINT IN THIS FILE.
headerView.bounces = NO;
Expand All @@ -44,7 +44,7 @@ - (void)viewDidLoad
self.headerView.minimumOfHeight = 64.0;
self.headerView.maximumOfHeight = 220.0;

AXSampleHeaderView *headerView = (id)self.headerView;
AXSampleSwipableHeaderView *headerView = (id)self.headerView;
headerView.textLabel.text = @"The Duomo in Firenze";
headerView.imageView.image = [UIImage imageNamed:@"sample-photo.jpg"];
[headerView.backButton setTitle:@"back" forState:UIControlStateNormal];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// AXSampleNoSwipableHeaderView.h
// StretchableHeaderTabViewExample
//

#import "AXStretchableHeaderView.h"

@interface AXSampleNoSwipableHeaderView : AXStretchableHeaderView

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AXSampleNoSwipableHeaderView.m
// StretchableHeaderTabViewExample
//

#import "AXSampleNoSwipableHeaderView.h"

@implementation AXSampleNoSwipableHeaderView

- (id)initWithFrame:(CGRect)frame
{
UINib *nib = [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
self = [[nib instantiateWithOwner:self options:nil] firstObject];
if (self) {
// Nothing to do, if you want to make no swipable header.
}
return self;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="bc0-DT-ocZ" customClass="AXSampleSwipableHeaderView">
<rect key="frame" x="0.0" y="0.0" width="320" height="333"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sample-photo.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="7eN-xe-VFm">
<rect key="frame" x="0.0" y="0.0" width="320" height="333"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.69999999999999996" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="7eN-xe-VFm" firstAttribute="top" secondItem="bc0-DT-ocZ" secondAttribute="top" id="Wbn-bY-q1v"/>
<constraint firstAttribute="trailing" secondItem="7eN-xe-VFm" secondAttribute="trailing" id="ci6-e5-saH"/>
<constraint firstItem="7eN-xe-VFm" firstAttribute="leading" secondItem="bc0-DT-ocZ" secondAttribute="leading" id="oXJ-Wb-VQR"/>
<constraint firstAttribute="bottom" secondItem="7eN-xe-VFm" secondAttribute="bottom" id="ort-eA-qbl"/>
</constraints>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="imageView" destination="7eN-xe-VFm" id="u7L-to-xf8"/>
<outlet property="topConstraint" destination="Wbn-bY-q1v" id="F6C-ot-c0O"/>
</connections>
</view>
</objects>
<resources>
<image name="sample-photo.jpg" width="960" height="460"/>
</resources>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// AXSampleNoSwipableTabViewController.h
// StretchableHeaderTabViewExample
//

#import "AXStretchableHeaderTabViewController.h"

@interface AXSampleNoSwipableTabViewController : AXStretchableHeaderTabViewController

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// AXSampleNoSwipableTabViewController.m
// StretchableHeaderTabViewExample
//

#import "AXSampleNoSwipableTabViewController.h"
#import "AXSub1TableViewController.h"
#import "AXSub2TableViewController.h"
#import "AXSampleNoSwipableHeaderView.h"

@implementation AXSampleNoSwipableTabViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"No horizontal swipe header";

AXSampleNoSwipableHeaderView *headerView = [[AXSampleNoSwipableHeaderView alloc] init];
self.headerView = headerView;

AXSub1TableViewController *sub1ViewCon = [[AXSub1TableViewController alloc] init];
AXSub2TableViewController *sub2ViewCon = [[AXSub2TableViewController alloc] init];

NSArray *viewControllers = @[sub1ViewCon, sub2ViewCon];
self.viewControllers = viewControllers;
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.headerView.minimumOfHeight = 64.0;
self.headerView.maximumOfHeight = 220.0;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

@end
Loading

0 comments on commit a7f4680

Please sign in to comment.