Skip to content

Commit

Permalink
Updated demo project
Browse files Browse the repository at this point in the history
Updated demo project to demonstrate the newly added functionalities.
  • Loading branch information
yichizhang committed Nov 29, 2014
1 parent d443cfa commit 9734493
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
@property (strong, nonatomic) UIWindow *window;
@property (strong) YZSwipeBetweenViewController *swipeBetweenVC;

- (void)setupRootViewControllerForWindow;

@end

Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,15 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor blackColor];

self.swipeBetweenVC = [YZSwipeBetweenViewController new];
[self setupRootViewControllerForWindow];
self.window.rootViewController = self.swipeBetweenVC;

UIViewController *vc1 = [DemoMainViewController new];
UINavigationController *navCon1 =
[[UINavigationController alloc]initWithRootViewController:vc1];

UIViewController *vc2 = [DemoMainViewController new];
UINavigationController *navCon2 =
[[UINavigationController alloc] initWithRootViewController:vc2];

UIViewController *vc3 = [DemoMainViewController new];
UINavigationController *navCon3 =
[[UINavigationController alloc] initWithRootViewController:vc3];

self.swipeBetweenVC.viewControllers = @[navCon1, navCon2, navCon3];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor blackColor];
[self.window setRootViewController:self.swipeBetweenVC];
[self.window makeKeyAndVisible];

return YES;
Expand Down Expand Up @@ -72,4 +60,23 @@ - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)setupRootViewControllerForWindow{

UIViewController *vc1 = [DemoMainViewController new];
UINavigationController *navCon1 =
[[UINavigationController alloc]initWithRootViewController:vc1];

UIViewController *vc2 = [DemoMainViewController new];
UINavigationController *navCon2 =
[[UINavigationController alloc] initWithRootViewController:vc2];

UIViewController *vc3 = [DemoMainViewController new];
UINavigationController *navCon3 =
[[UINavigationController alloc] initWithRootViewController:vc3];

self.swipeBetweenVC.viewControllers = @[navCon1, navCon2, navCon3];
self.swipeBetweenVC.initialViewControllerIndex = self.swipeBetweenVC.viewControllers.count/2;

}

@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6250" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand All @@ -11,13 +11,13 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2014 Yichi Zhang. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="YZSwipeBetweenViewController" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="YZSwipeBetweenViewControllerDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Demo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
*/

#import "DemoMainViewController.h"
#import "AppDelegate.h"

@interface DemoMainViewController ()

@property (nonatomic, strong) UIButton *pushVCButton;
@property (nonatomic, strong) UIButton *scrollVCButton;
@property (nonatomic, strong) UISegmentedControl *segControl;
@property (nonatomic, strong) UIButton *changeVCsButton;
@property (nonatomic, strong) UILabel *viewControllerDetailLabel;

@end

@implementation DemoMainViewController
Expand All @@ -29,15 +36,95 @@ - (void)viewDidLoad {
self.view.backgroundColor = [UIColor colorWithHue:randomNum saturation:1.0 brightness:1.0 alpha:1.0];

self.title = @"Demo VC";

UIColor *fgColor = [UIColor colorWithWhite:1.0 alpha:1.00];
UIColor *bgColor = [UIColor colorWithWhite:0.0 alpha:0.75];



self.pushVCButton = [[UIButton alloc] initWithFrame:CGRectZero];
[self.pushVCButton setTitle:@"Push a VC" forState:UIControlStateNormal];
[self.pushVCButton setTitleColor:fgColor forState:UIControlStateNormal];
[self.pushVCButton setBackgroundColor:bgColor];

[self.pushVCButton addTarget:self action:@selector(pushVCButtonTapped:) forControlEvents:UIControlEventTouchDown];

[self.view addSubview:self.pushVCButton];



self.scrollVCButton = [[UIButton alloc] initWithFrame:CGRectZero];
[self.scrollVCButton setTitle:@"Scroll To: (Select From Below)" forState:UIControlStateNormal];
[self.scrollVCButton setTitleColor:fgColor forState:UIControlStateNormal];
[self.scrollVCButton setBackgroundColor:bgColor];

[self.scrollVCButton addTarget:self action:@selector(scrollVCButtonTapped:) forControlEvents:UIControlEventTouchDown];

[self.view addSubview:self.scrollVCButton];



self.changeVCsButton = [[UIButton alloc] initWithFrame:CGRectZero];
[self.changeVCsButton setTitle:@"Replace All The VCs" forState:UIControlStateNormal];
[self.changeVCsButton setTitleColor:fgColor forState:UIControlStateNormal];
[self.changeVCsButton setBackgroundColor:bgColor];

[self.changeVCsButton addTarget:self action:@selector(changeVCsButtonTapped:) forControlEvents:UIControlEventTouchDown];

[self.view addSubview:self.changeVCsButton];




UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
[button setTitle:@"Tap" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.segControl = [[UISegmentedControl alloc]
initWithItems:@[
@"Index: 0",
@"Index: 1",
@"Index: 2"
]
];
self.segControl.tintColor = fgColor;
self.segControl.backgroundColor = bgColor;
[self.view addSubview:self.segControl];

[self.view addSubview:button];
button.center = self.view.center;



self.viewControllerDetailLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.viewControllerDetailLabel.textColor = fgColor;
self.viewControllerDetailLabel.backgroundColor = bgColor;
self.viewControllerDetailLabel.text = self.description;
[self.view addSubview:self.viewControllerDetailLabel];



[self.segControl sizeToFit];

[self.pushVCButton sizeToFit];
[self.scrollVCButton sizeToFit];
[self.changeVCsButton sizeToFit];
[self.viewControllerDetailLabel sizeToFit];


}

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchDown];
- (void)viewDidLayoutSubviews{

[super viewDidLayoutSubviews];

float centerY = self.view.center.y*0.4;
float centerX = self.view.center.x;
float buttonHeight = 36;

self.pushVCButton.center = CGPointMake(centerX, centerY);
centerY += buttonHeight*2;
self.scrollVCButton.center = CGPointMake(centerX, centerY);
centerY += buttonHeight;
self.segControl.center = CGPointMake(centerX, centerY);
centerY += buttonHeight*2;
self.changeVCsButton.center = CGPointMake(centerX, centerY);
centerY += buttonHeight*2;
self.viewControllerDetailLabel.center = CGPointMake(centerX, centerY);

}

Expand All @@ -46,13 +133,26 @@ - (void)didReceiveMemoryWarning {
// Dispose of any resources that can be recreated.
}

- (void)buttonTapped:(id)sender{
- (void)pushVCButtonTapped:(id)sender{

UIViewController *vc = [DemoMainViewController new];
[self.navigationController pushViewController:vc animated:YES];

}

- (void)scrollVCButtonTapped:(id)sender{

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.swipeBetweenVC scrollToViewControllerAtIndex:self.segControl.selectedSegmentIndex];

}

- (void)changeVCsButtonTapped:(id)sender{

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate setupRootViewControllerForWindow];

}
/*
#pragma mark - Navigation
Expand Down

0 comments on commit 9734493

Please sign in to comment.