forked from yeatse/YTPageController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
402 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
Example/YTPageController/Dynamic Pages/DynamicPages.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="66Y-dS-GAl"> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/> | ||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Dynamic Pages--> | ||
<scene sceneID="6bz-6h-j9u"> | ||
<objects> | ||
<viewController title="Dynamic Pages" id="66Y-dS-GAl" customClass="DynamicPagesViewController" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="dlh-G6-DSn"/> | ||
<viewControllerLayoutGuide type="bottom" id="ggm-Wk-QDu"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="ZJQ-OK-dYz"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<tabBar contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="N5B-ql-jbb"> | ||
<frame key="frameInset" height="49"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> | ||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | ||
<items/> | ||
<connections> | ||
<outlet property="delegate" destination="66Y-dS-GAl" id="Ug9-1G-FiG"/> | ||
</connections> | ||
</tabBar> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | ||
</view> | ||
<navigationItem key="navigationItem" title="Dynamic Pages" id="JBp-jT-Hvp"> | ||
<barButtonItem key="rightBarButtonItem" title="Reload" id="i26-AO-lpk"> | ||
<connections> | ||
<action selector="reloadPages:" destination="66Y-dS-GAl" id="JcH-DP-UlG"/> | ||
</connections> | ||
</barButtonItem> | ||
</navigationItem> | ||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/> | ||
<userDefinedRuntimeAttributes> | ||
<userDefinedRuntimeAttribute type="boolean" keyPath="bounces" value="YES"/> | ||
</userDefinedRuntimeAttributes> | ||
<connections> | ||
<outlet property="tabBar" destination="N5B-ql-jbb" id="HlG-5S-8oE"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="BSj-Q8-mSl" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="220" y="114"/> | ||
</scene> | ||
<!--Child View Controller--> | ||
<scene sceneID="wTU-GT-zRj"> | ||
<objects> | ||
<viewController storyboardIdentifier="ChildViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="Nwk-LD-gE9" userLabel="Child View Controller" customClass="DynamicPagesChildViewController" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="MLV-m9-qyy"/> | ||
<viewControllerLayoutGuide type="bottom" id="hXp-hT-GIl"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="4CR-DT-ZeE"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QeT-e9-Ieh"> | ||
<fontDescription key="fontDescription" type="system" pointSize="25"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="QeT-e9-Ieh" firstAttribute="top" secondItem="4CR-DT-ZeE" secondAttribute="topMargin" constant="156" id="7Fr-PZ-QtU"/> | ||
<constraint firstItem="QeT-e9-Ieh" firstAttribute="centerX" secondItem="4CR-DT-ZeE" secondAttribute="centerX" id="J2N-h0-x4x"/> | ||
</constraints> | ||
</view> | ||
<connections> | ||
<outlet property="label" destination="QeT-e9-Ieh" id="TBQ-WN-CkW"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="Rec-jv-gqm" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="1047" y="114"/> | ||
</scene> | ||
</scenes> | ||
</document> |
15 changes: 15 additions & 0 deletions
15
Example/YTPageController/Dynamic Pages/DynamicPagesChildViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// DynamicPagesChildViewController.h | ||
// YTPageController | ||
// | ||
// Created by yeatse on 16/9/21. | ||
// Copyright © 2016年 Yeatse CC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface DynamicPagesChildViewController : UIViewController | ||
|
||
@property (weak, nonatomic) IBOutlet UILabel *label; | ||
|
||
@end |
26 changes: 26 additions & 0 deletions
26
Example/YTPageController/Dynamic Pages/DynamicPagesChildViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// DynamicPagesChildViewController.m | ||
// YTPageController | ||
// | ||
// Created by yeatse on 16/9/21. | ||
// Copyright © 2016年 Yeatse CC. All rights reserved. | ||
// | ||
|
||
#import "DynamicPagesChildViewController.h" | ||
|
||
@interface DynamicPagesChildViewController () | ||
|
||
@end | ||
|
||
@implementation DynamicPagesChildViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.label.text = self.title; | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
} | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
Example/YTPageController/Dynamic Pages/DynamicPagesViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DynamicPagesViewController.h | ||
// YTPageController | ||
// | ||
// Created by yeatse on 16/9/21. | ||
// Copyright © 2016年 Yeatse CC. All rights reserved. | ||
// | ||
|
||
#import <YTPageController/YTPageController.h> | ||
|
||
@interface DynamicPagesViewController : YTPageController | ||
|
||
@end |
96 changes: 96 additions & 0 deletions
96
Example/YTPageController/Dynamic Pages/DynamicPagesViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// DynamicPagesViewController.m | ||
// YTPageController | ||
// | ||
// Created by yeatse on 16/9/21. | ||
// Copyright © 2016年 Yeatse CC. All rights reserved. | ||
// | ||
|
||
#import "DynamicPagesViewController.h" | ||
#import "DynamicPagesChildViewController.h" | ||
|
||
@interface DynamicPagesViewController ()<YTPageControllerDelegate, YTPageControllerDataSource, UITabBarDelegate> | ||
|
||
@property (weak, nonatomic) IBOutlet UITabBar *tabBar; | ||
|
||
@end | ||
|
||
@implementation DynamicPagesViewController { | ||
NSArray<NSString*>* _pageNames1; | ||
NSArray<NSString*>* _pageNames2; | ||
BOOL _flag; | ||
} | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.delegate = self; | ||
self.dataSource = self; | ||
|
||
_pageNames1 = @[@"First", @"Second", @"Third"]; | ||
_pageNames2 = @[@"Eins", @"Zwei", @"Drei", @"Vier"]; | ||
|
||
[self reloadPages]; | ||
[self refreshTabBarItems]; | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
} | ||
|
||
- (IBAction)reloadPages:(id)sender { | ||
_flag = !_flag; | ||
self.currentIndex = 0; | ||
[self reloadPages]; | ||
[self refreshTabBarItems]; | ||
} | ||
|
||
- (void)refreshTabBarItems { | ||
NSMutableArray<UITabBarItem*>* items = @[].mutableCopy; | ||
for (NSString* name in _flag ? _pageNames2 : _pageNames1) { | ||
UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:name image:[UIImage imageNamed:@"tabbar_icon"] selectedImage:[UIImage imageNamed:@"tabbar_icon_hl"]]; | ||
[items addObject:item]; | ||
} | ||
self.tabBar.items = items; | ||
self.tabBar.selectedItem = self.tabBar.items[self.currentIndex]; | ||
} | ||
|
||
#pragma mark - YTPageControllerDelegate | ||
|
||
- (void)pageController:(YTPageController *)pageController willTransitionToIndex:(NSInteger)index { | ||
[self.pageCoordinator animateAlongsidePagingInView:self.tabBar animation:^(id<YTPageTransitionContext> _Nonnull context) { | ||
self.tabBar.selectedItem = self.tabBar.items[[context toIndex]]; | ||
} completion:^(id<YTPageTransitionContext> _Nonnull context) { | ||
if ([context isCanceled]) { | ||
self.tabBar.selectedItem = self.tabBar.items[[context fromIndex]]; | ||
} | ||
}]; | ||
} | ||
|
||
- (void)pageController:(YTPageController *)pageController didUpdateTransition:(id<YTPageTransitionContext>)context { | ||
NSLog(@"%s, offset: %f", __func__, [context relativeOffset]); | ||
} | ||
|
||
- (void)pageController:(YTPageController *)pageController didEndTransition:(id<YTPageTransitionContext>)context { | ||
NSLog(@"%s from %zd to %zd, canceled: %d", __func__, [context fromIndex], [context toIndex], [context isCanceled]); | ||
} | ||
|
||
#pragma mark - YTPageControllerDataSource | ||
|
||
- (NSInteger)numberOfPagesInPageController:(YTPageController *)pageController { | ||
return _flag ? _pageNames2.count : _pageNames1.count; | ||
} | ||
|
||
- (UIViewController *)pageController:(YTPageController *)pageController pageAtIndex:(NSInteger)index { | ||
DynamicPagesChildViewController* childVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController"]; | ||
childVC.title = (_flag ? _pageNames2 : _pageNames1)[index]; | ||
return childVC; | ||
} | ||
|
||
#pragma mark - UITabBarDelegate | ||
|
||
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { | ||
self.currentIndex = [tabBar.items indexOfObjectIdenticalTo:item]; | ||
} | ||
|
||
@end |
Oops, something went wrong.