Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion YSLContainerViewController/YSLContainerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@property (nonatomic, strong, readonly) NSMutableArray *titles;
@property (nonatomic, strong, readonly) NSMutableArray *childControllers;

@property (nonatomic, readonly) NSUInteger currentIndex;

@property (nonatomic, strong) UIFont *menuItemFont;
@property (nonatomic, strong) UIColor *menuItemTitleColor;
@property (nonatomic, strong) UIColor *menuItemSelectedTitleColor;
Expand All @@ -30,6 +32,8 @@

- (id)initWithControllers:(NSArray *)controllers
topBarHeight:(CGFloat)topBarHeight
parentViewController:(UIViewController *)parentViewController;
parentViewController:(UIViewController *)parentViewController
withCurrentIndex:(NSUInteger)currentIndex;
- (void)selectViewControllerAtIndex:(NSUInteger)index;

@end
15 changes: 11 additions & 4 deletions YSLContainerViewController/YSLContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@interface YSLContainerViewController () <UIScrollViewDelegate, YSLScrollMenuViewDelegate>

@property (nonatomic, assign) CGFloat topBarHeight;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, readwrite) NSUInteger currentIndex;
@property (nonatomic, strong) YSLScrollMenuView *menuView;

@end
Expand All @@ -24,6 +24,7 @@ @implementation YSLContainerViewController
- (id)initWithControllers:(NSArray *)controllers
topBarHeight:(CGFloat)topBarHeight
parentViewController:(UIViewController *)parentViewController
withCurrentIndex:(NSUInteger)currentIndex
{
self = [super init];
if (self) {
Expand All @@ -32,16 +33,16 @@ - (id)initWithControllers:(NSArray *)controllers
[self didMoveToParentViewController:parentViewController];

_topBarHeight = topBarHeight;
_titles = [[NSMutableArray alloc] init];
_childControllers = [[NSMutableArray alloc] init];
_childControllers = [controllers mutableCopy];

NSMutableArray *titles = [NSMutableArray array];
for (UIViewController *vc in _childControllers) {
[titles addObject:[vc valueForKey:@"title"]];
}
_titles = [titles mutableCopy];
_currentIndex = currentIndex;
}

return self;
}

Expand Down Expand Up @@ -91,7 +92,12 @@ - (void)viewDidLoad {
[self.view addSubview:_menuView];
[_menuView setShadowView];

[self scrollMenuViewSelectedIndex:0];
// self.currentIndex = 0;
[self scrollMenuViewSelectedIndex:self.currentIndex];
}

- (void)selectViewControllerAtIndex:(NSUInteger)index {
[self scrollMenuViewSelectedIndex:index];
}

#pragma mark -- private
Expand All @@ -114,6 +120,7 @@ - (void)setChildViewControllerWithCurrentIndex:(NSInteger)currentIndex
}
}
}

#pragma mark -- YSLScrollMenuView Delegate

- (void)scrollMenuViewSelectedIndex:(NSInteger)index
Expand Down
18 changes: 12 additions & 6 deletions YSLContainerViewControllerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
04C799481F286DFF00D5D456 /* InitialViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04C799471F286DFF00D5D456 /* InitialViewController.m */; };
D098129D1AC165570085833D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D098129C1AC165570085833D /* main.m */; };
D09812A01AC165570085833D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D098129F1AC165570085833D /* AppDelegate.m */; };
D09812A31AC165570085833D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D09812A21AC165570085833D /* ViewController.m */; };
D09812A31AC165570085833D /* ContainerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D09812A21AC165570085833D /* ContainerViewController.m */; };
D09812A61AC165570085833D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D09812A41AC165570085833D /* Main.storyboard */; };
D09812A81AC165570085833D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D09812A71AC165570085833D /* Images.xcassets */; };
D09812AB1AC165570085833D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D09812A91AC165570085833D /* LaunchScreen.xib */; };
Expand Down Expand Up @@ -49,13 +50,15 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
04C799461F286DFF00D5D456 /* InitialViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InitialViewController.h; sourceTree = "<group>"; };
04C799471F286DFF00D5D456 /* InitialViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InitialViewController.m; sourceTree = "<group>"; };
D09812971AC165570085833D /* YSLContainerViewControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YSLContainerViewControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
D098129B1AC165570085833D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D098129C1AC165570085833D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
D098129E1AC165570085833D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
D098129F1AC165570085833D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
D09812A11AC165570085833D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
D09812A21AC165570085833D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
D09812A11AC165570085833D /* ContainerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContainerViewController.h; sourceTree = "<group>"; };
D09812A21AC165570085833D /* ContainerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContainerViewController.m; sourceTree = "<group>"; };
D09812A51AC165570085833D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
D09812A71AC165570085833D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
D09812AA1AC165570085833D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -139,8 +142,10 @@
D09812CD1AC27EB70085833D /* cells */,
D098129E1AC165570085833D /* AppDelegate.h */,
D098129F1AC165570085833D /* AppDelegate.m */,
D09812A11AC165570085833D /* ViewController.h */,
D09812A21AC165570085833D /* ViewController.m */,
04C799461F286DFF00D5D456 /* InitialViewController.h */,
04C799471F286DFF00D5D456 /* InitialViewController.m */,
D09812A11AC165570085833D /* ContainerViewController.h */,
D09812A21AC165570085833D /* ContainerViewController.m */,
D09812A41AC165570085833D /* Main.storyboard */,
D09812A71AC165570085833D /* Images.xcassets */,
D09812A91AC165570085833D /* LaunchScreen.xib */,
Expand Down Expand Up @@ -350,8 +355,9 @@
buildActionMask = 2147483647;
files = (
D09812F11AC288440085833D /* SampleViewController.m in Sources */,
D09812A31AC165570085833D /* ViewController.m in Sources */,
D09812A31AC165570085833D /* ContainerViewController.m in Sources */,
D09812A01AC165570085833D /* AppDelegate.m in Sources */,
04C799481F286DFF00D5D456 /* InitialViewController.m in Sources */,
D09812E71AC2849B0085833D /* ArtistsViewController.m in Sources */,
D098129D1AC165570085833D /* main.m in Sources */,
D09812EC1AC285520085833D /* ArtistsCell.m in Sources */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions YSLContainerViewControllerDemo/ArtistsCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ @implementation ArtistsCell

- (void)awakeFromNib {
// Initialization code
[super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
Expand Down
82 changes: 71 additions & 11 deletions YSLContainerViewControllerDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="TDC-gT-HD1">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="TDC-gT-HD1">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Container View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="ContainerViewController" id="vXZ-lx-hvc" customClass="ContainerViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" id="5YF-mX-aLd"/>
<navigationItem key="navigationItem" id="5YF-mX-aLd">
<barButtonItem key="rightBarButtonItem" systemItem="play" id="MMQ-IE-cqF">
<connections>
<action selector="goToNextViewController:" destination="vXZ-lx-hvc" id="AAq-Nn-yKQ"/>
</connections>
</barButtonItem>
</navigationItem>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="352" y="210"/>
<point key="canvasLocation" x="1249" y="209"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="KQZ-9S-N8x">
Expand All @@ -33,12 +43,62 @@
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="ad6-Hp-2s5"/>
<segue destination="SSB-RN-9wQ" kind="relationship" relationship="rootViewController" id="slO-nk-wTc"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="QVT-Jy-ZfT" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-310" y="210"/>
</scene>
<!--Initial View Controller-->
<scene sceneID="Zhc-7D-MQq">
<objects>
<viewController storyboardIdentifier="InitialViewController" id="SSB-RN-9wQ" customClass="InitialViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="V3z-b4-VZ0"/>
<viewControllerLayoutGuide type="bottom" id="xAC-qW-hu4"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="1OY-eo-NaM">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NI9-qe-CgS">
<rect key="frame" x="58" y="316.5" width="258" height="33"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="17"/>
<state key="normal" title="Second View Controller Selected">
<color key="titleColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onTapSecondViewControllerButton:" destination="SSB-RN-9wQ" eventType="touchUpInside" id="tF4-nl-CHT"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gsd-jE-QBL">
<rect key="frame" x="70.5" y="275.5" width="233" height="33"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="17"/>
<state key="normal" title="First View Controller Selected">
<color key="titleColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onTapFirstViewControllerButton:" destination="SSB-RN-9wQ" eventType="touchUpInside" id="T88-jZ-Oym"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="NI9-qe-CgS" firstAttribute="centerY" secondItem="1OY-eo-NaM" secondAttribute="centerY" id="5RO-SA-nP6"/>
<constraint firstItem="gsd-jE-QBL" firstAttribute="centerX" secondItem="1OY-eo-NaM" secondAttribute="centerX" id="LKM-OW-D8Z"/>
<constraint firstItem="NI9-qe-CgS" firstAttribute="centerX" secondItem="1OY-eo-NaM" secondAttribute="centerX" id="tbb-7O-XUy"/>
<constraint firstItem="NI9-qe-CgS" firstAttribute="top" secondItem="gsd-jE-QBL" secondAttribute="bottom" constant="8" id="w4d-lh-FNj"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="fAa-kg-iW6"/>
<connections>
<segue destination="vXZ-lx-hvc" kind="show" identifier="ContainerSegue" id="wDn-Bx-cZT"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="tuM-sI-TyZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="463" y="209"/>
</scene>
</scenes>
</document>
18 changes: 18 additions & 0 deletions YSLContainerViewControllerDemo/ContainerViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ContainerViewController.h
// YSLContainerViewControllerDemo
//
// Created by yamaguchi on 2015/03/24.
// Copyright (c) 2015年 h.yamaguchi. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ContainerViewController : UIViewController

@property (nonatomic, nonnull) NSNumber *defaultIndex;

- (IBAction)goToNextViewController:(id _Nullable)sender;

@end

Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
//
// ViewController.m
// ContainerViewController.m
// YSLContainerViewControllerDemo
//
// Created by yamaguchi on 2015/03/24.
// Copyright (c) 2015年 h.yamaguchi. All rights reserved.
//

#import "ViewController.h"
#import "ContainerViewController.h"
#import "YSLContainerViewController.h"
#import "PlayListTableViewController.h"
#import "ArtistsViewController.h"
#import "SampleViewController.h"

@interface ViewController () <YSLContainerViewControllerDelegate>
@interface ContainerViewController () <YSLContainerViewControllerDelegate>

@property (strong, nonatomic) YSLContainerViewController *container;

@end

@implementation ViewController
@implementation ContainerViewController

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
Expand Down Expand Up @@ -54,13 +56,21 @@ - (void)viewDidLoad {
float statusHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
float navigationHeight = self.navigationController.navigationBar.frame.size.height;

YSLContainerViewController *containerVC = [[YSLContainerViewController alloc]initWithControllers:@[playListVC,artistVC,sampleVC1,sampleVC2,sampleVC3]
self.container = [[YSLContainerViewController alloc]initWithControllers:@[playListVC,artistVC,sampleVC1,sampleVC2,sampleVC3]
topBarHeight:statusHeight + navigationHeight
parentViewController:self];
containerVC.delegate = self;
containerVC.menuItemFont = [UIFont fontWithName:@"Futura-Medium" size:16];
parentViewController:self
withCurrentIndex:self.defaultIndex.integerValue];
self.container.delegate = self;
self.container.menuItemFont = [UIFont fontWithName:@"Futura-Medium" size:16];

[self.view addSubview:self.container.view];
}

- (IBAction)goToNextViewController:(id)sender {

[self.view addSubview:containerVC.view];
NSInteger currentIndex = self.container.currentIndex;
NSInteger nextIndex = (++currentIndex >= self.container.childControllers.count) ? 0 : currentIndex;
[self.container selectViewControllerAtIndex:nextIndex];
}

#pragma mark -- YSLContainerViewControllerDelegate
Expand Down
16 changes: 16 additions & 0 deletions YSLContainerViewControllerDemo/InitialViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// InitialViewController.h
// YSLContainerViewControllerDemo
//
// Created by Adeel Miraj on 26/07/2017.
// Copyright © 2017 h.yamaguchi. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface InitialViewController : UIViewController

- (IBAction)onTapFirstViewControllerButton:(UIButton *)sender;
- (IBAction)onTapSecondViewControllerButton:(UIButton *)sender;

@end
Loading