Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b29e9c0

Browse files
SergeySergey
authored andcommitted
implement pod
1 parent 40667ed commit b29e9c0

File tree

156 files changed

+5338
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+5338
-8
lines changed

CRPageViewController.podspec

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# Be sure to run `pod lib lint CRPageViewController.podspec' to ensure this is a
3+
# valid spec before submitting.
4+
#
5+
# Any lines starting with a # are optional, but their use is encouraged
6+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
7+
#
8+
9+
Pod::Spec.new do |s|
10+
s.name = 'CRPageViewController'
11+
s.version = '0.1.0'
12+
s.summary = 'A short description of CRPageViewController.'
13+
14+
# This description is used to generate tags and improve search results.
15+
# * Think: What does it do? Why did you write it? What is the focus?
16+
# * Try to keep it short, snappy and to the point.
17+
# * Write the description between the DESC delimiters below.
18+
# * Finally, don't worry about the indent, CocoaPods strips it!
19+
20+
s.description = <<-DESC
21+
TODO: Add long description of the pod here.
22+
DESC
23+
24+
s.homepage = 'https://github.com/<GITHUB_USERNAME>/CRPageViewController'
25+
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
26+
s.license = { :type => 'MIT', :file => 'LICENSE' }
27+
s.author = { 'Sergey' => '[email protected]' }
28+
s.source = { :git => 'https://github.com/<GITHUB_USERNAME>/CRPageViewController.git', :tag => s.version.to_s }
29+
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
30+
31+
s.ios.deployment_target = '8.0'
32+
33+
s.source_files = 'CRPageViewController/Classes/**/*'
34+
35+
# s.resource_bundles = {
36+
# 'CRPageViewController' => ['CRPageViewController/Assets/*.png']
37+
# }
38+
39+
# s.public_header_files = 'Pod/Classes/**/*.h'
40+
# s.frameworks = 'UIKit', 'MapKit'
41+
# s.dependency 'AFNetworking', '~> 2.3'
42+
end

CRPageViewController/Assets/.gitkeep

Whitespace-only changes.

CRPageViewController/Classes/.gitkeep

Whitespace-only changes.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//
2+
// CRPageViewController.h
3+
// Pods
4+
//
5+
// Created by Sergey Chuchukalo on 5/25/16.
6+
//
7+
// Copyright © 2016 Cleveroad Inc. All rights reserved.
8+
9+
#import <UIKit/UIKit.h>
10+
@class CRPageViewController;
11+
12+
@protocol CRPageViewControllerDataSource <NSObject>
13+
@required
14+
/**
15+
* Returns the view controller after the given view controller.
16+
*
17+
* @param pageViewController The page view controller
18+
* @param viewController The view controller that the user navigated away from.
19+
* @return The view controller after the given view controller, or nil to indicate that there is no next view controller.
20+
*/
21+
- (UIViewController *)pageViewController:(CRPageViewController *)pageViewController
22+
viewControllerAfterViewController:(UIViewController *)viewController;
23+
24+
/**
25+
* Returns the view controller before the given view controller.
26+
* @param pageViewController The page view controller
27+
* @param viewController The view controller that the user navigated away from.
28+
* @return The view controller before the given view controller, or nil to indicate that there is no previous view controller.
29+
*/
30+
- (UIViewController *)pageViewController:(CRPageViewController *)pageViewController
31+
viewControllerBeforeViewController:(UIViewController *)viewController;
32+
33+
@optional
34+
/**
35+
* ViewController moving to center PageController
36+
*
37+
* @param viewController is ViewController what moving to center PageController
38+
*/
39+
- (void)focusedViewController:(UIViewController *)viewController;
40+
41+
/**
42+
* ViewController moving from center PageController
43+
*
44+
* @param viewController is ViewController what moving from center PageController
45+
*/
46+
- (void)unfocusedViewController:(UIViewController *)viewController;
47+
@end
48+
49+
/**
50+
* CRPageViewController is customise PageViewController. CRPageViewController allows implement cards form of UIViewController.
51+
*/
52+
@interface CRPageViewController : UIViewController
53+
54+
/**
55+
* DataSourse of PageViewController
56+
*/
57+
@property (weak, nonatomic) id <CRPageViewControllerDataSource> dataSource;
58+
59+
/**
60+
* Starting array of UIViewController in PageViewController
61+
*/
62+
@property (strong, nonatomic) NSArray <UIViewController*> *viewControllers;
63+
/**
64+
* Size of UIViewController in PageViewController
65+
*/
66+
@property (assign, nonatomic) CGSize childVCSize;
67+
68+
/**
69+
* Vertical offset of UIViewController in center screen
70+
*/
71+
@property (assign, nonatomic) CGFloat OffsetOfHeightCentralVC;
72+
73+
/**
74+
* Distance between child UIViewController
75+
*/
76+
@property (assign, nonatomic) CGFloat sizeBetweenVC;
77+
78+
/**
79+
* Speed of animation change UIViewController on center PageViewController
80+
*/
81+
@property (assign, nonatomic) CGFloat animationSpeed;
82+
83+
/**
84+
* Type of animation change UIViewController on center PageViewController
85+
*/
86+
@property (assign, nonatomic) UIViewAnimationCurve animation;
87+
88+
/**
89+
* Count of UIViewController on PageViewController
90+
*/
91+
@property (assign, nonatomic) NSInteger countPageInController;
92+
93+
@end
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
//
2+
// CRPageViewController.m
3+
// Pods
4+
//
5+
// Created by Sergey Chuchukalo on 5/25/16.
6+
//
7+
// Copyright © 2016 Cleveroad Inc. All rights reserved.
8+
9+
#import "CRPageViewController.h"
10+
11+
@interface CRPageViewController () <UIGestureRecognizerDelegate>
12+
13+
- (void)slideToRightWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer;
14+
- (void)slideToLeftWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer;
15+
@property (strong, nonatomic) NSMutableArray <UIViewController*> * internalViewControllers;
16+
@property (assign, nonatomic) CGFloat spaceHorizontal;
17+
@property (assign, nonatomic) CGFloat spaceVertical;
18+
19+
@end
20+
21+
@implementation CRPageViewController
22+
23+
#pragma mark - Life circle VC
24+
25+
- (void)viewDidLoad {
26+
[super viewDidLoad];
27+
28+
UISwipeGestureRecognizer *swipeRightOrange = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
29+
swipeRightOrange.direction = UISwipeGestureRecognizerDirectionRight;
30+
[self.view addGestureRecognizer:swipeRightOrange];
31+
UISwipeGestureRecognizer *swipeLeftOrange = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToLeftWithGestureRecognizer:)];
32+
swipeLeftOrange.direction = UISwipeGestureRecognizerDirectionLeft;
33+
[self.view addGestureRecognizer:swipeLeftOrange];
34+
}
35+
36+
- (void)viewDidAppear:(BOOL)animated {
37+
[super viewDidAppear:animated];
38+
39+
self.spaceHorizontal = (self.view.frame.size.width - self.childVCSize.width) / 2;
40+
self.spaceVertical = (self.view.frame.size.height - self.childVCSize.height) / 2;
41+
self.internalViewControllers = [NSMutableArray new];
42+
for (UIViewController* vc in self.viewControllers) {
43+
[self pushRightViewController:vc];
44+
}
45+
[self changeViewControllersWithNumber:self.countPageInController/2];
46+
[self performSelector:@selector(focusedCentralView) withObject:nil afterDelay:0.2];
47+
}
48+
49+
- (void)focusedCentralView {
50+
if ([self.dataSource respondsToSelector:@selector(focusedViewController:)]) {
51+
[self.dataSource focusedViewController:self.internalViewControllers[self.countPageInController/2]];
52+
}
53+
}
54+
55+
- (void)setSizeBetweenVC:(CGFloat)sizeBetweenVC {
56+
_sizeBetweenVC = sizeBetweenVC;
57+
[self changeViewControllersWithNumber:self.countPageInController/2];
58+
}
59+
60+
- (void)setChildVCSize:(CGSize)childVCSize {
61+
_childVCSize = childVCSize;
62+
self.spaceHorizontal = (self.view.frame.size.width - self.childVCSize.width) / 2;
63+
self.spaceVertical = (self.view.frame.size.height - self.childVCSize.height) / 2;
64+
[self changeViewControllersWithNumber:self.countPageInController/2];
65+
66+
}
67+
68+
- (void)setOffsetOfHeightCentralVC:(CGFloat)OffsetOfHeightCentralVC {
69+
_OffsetOfHeightCentralVC = OffsetOfHeightCentralVC;
70+
[self changeViewControllersWithNumber:self.countPageInController/2];
71+
}
72+
73+
#pragma mark - Push VC
74+
75+
- (void)pushRightViewController:(__kindof UIViewController *)viewController {
76+
viewController.view.frame = CGRectMake(self.view.frame.size.width,
77+
self.spaceVertical,
78+
self.childVCSize.width,
79+
self.childVCSize.height);
80+
[self createViewController:viewController];
81+
[self.internalViewControllers addObject:viewController];
82+
[self changeViewControllersWithNumber:self.countPageInController/2];
83+
}
84+
85+
- (void)pushLeftViewController:(__kindof UIViewController *)viewController {
86+
viewController.view.frame = CGRectMake(0,
87+
self.spaceVertical,
88+
self.childVCSize.width,
89+
self.childVCSize.height);
90+
[self createViewController:viewController];
91+
[self.internalViewControllers insertObject:viewController atIndex:0];
92+
[self changeViewControllersWithNumber:self.countPageInController/2 + 1];
93+
}
94+
95+
# pragma mark - gestureRecognizers
96+
97+
- (void)slideToRightWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer{
98+
if ([self.dataSource respondsToSelector:@selector(pageViewController:viewControllerBeforeViewController:)]) {
99+
UIViewController *newViewController = [self.dataSource pageViewController:self viewControllerBeforeViewController:self.internalViewControllers.firstObject];
100+
if (newViewController) {
101+
[self unfocused:self.countPageInController/2];
102+
[self pushLeftViewController:newViewController];
103+
[UIView animateKeyframesWithDuration:self.animationSpeed delay:0 options:self.animation animations:^{
104+
[self changeViewControllersWithNumber:self.countPageInController/2];
105+
if ([self.dataSource respondsToSelector:@selector(focusedViewController:)]) {
106+
[self.dataSource focusedViewController:self.internalViewControllers[self.countPageInController/2]];
107+
}
108+
} completion:^(BOOL finished) {
109+
}];
110+
[self performSelector:@selector(popRightViewCintroller) withObject:nil afterDelay:self.animationSpeed];
111+
}
112+
}
113+
}
114+
115+
- (void)slideToLeftWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer {
116+
if ([self.dataSource respondsToSelector:@selector(pageViewController:viewControllerAfterViewController:)]) {
117+
UIViewController *newViewController = [self.dataSource pageViewController:self viewControllerAfterViewController:self.internalViewControllers.lastObject];
118+
if (newViewController) {
119+
[self unfocused:self.countPageInController/2];
120+
[self pushRightViewController:newViewController];
121+
[UIView animateKeyframesWithDuration:self.animationSpeed delay:0 options:self.animation animations:^{
122+
[self changeViewControllersWithNumber:self.countPageInController/2 + 1];
123+
if ([self.dataSource respondsToSelector:@selector(focusedViewController:)]) {
124+
[self.dataSource focusedViewController:self.internalViewControllers[self.countPageInController/2 + 1]];
125+
}
126+
} completion:^(BOOL finished) {
127+
}];
128+
[self performSelector:@selector(popLeftViewCintroller) withObject:nil afterDelay:self.animationSpeed];
129+
}
130+
}
131+
}
132+
133+
#pragma mark - Helpers
134+
135+
- (void)popRightViewCintroller {
136+
if (self.internalViewControllers.count >= 0) {
137+
[self removeViewController:self.internalViewControllers.lastObject];
138+
[self.internalViewControllers removeLastObject];
139+
[self changeViewControllersWithNumber:self.countPageInController/2];
140+
}
141+
}
142+
143+
- (void)popLeftViewCintroller {
144+
if (self.internalViewControllers.count >= 0) {
145+
[self removeViewController:self.internalViewControllers.firstObject];
146+
[self.internalViewControllers removeObjectAtIndex:0];
147+
[self changeViewControllersWithNumber:self.countPageInController/2];
148+
}
149+
}
150+
151+
- (void)createViewController:(__kindof UIViewController *)viewController {
152+
[self addChildViewController:viewController];
153+
[self.view addSubview:viewController.view];
154+
[viewController didMoveToParentViewController:self];
155+
}
156+
157+
- (void)removeViewController:(__kindof UIViewController *)viewController {
158+
[viewController willMoveToParentViewController:nil];
159+
[viewController.view removeFromSuperview];
160+
[viewController removeFromParentViewController];
161+
}
162+
163+
- (void)unfocused:(NSInteger)numberOfFocusetView {
164+
if (self.internalViewControllers.count == self.countPageInController) {
165+
if ([self.dataSource respondsToSelector:@selector(unfocusedViewController:)]) {
166+
[self.dataSource unfocusedViewController:self.internalViewControllers[numberOfFocusetView]];
167+
}
168+
}
169+
}
170+
171+
- (void)changeViewControllersWithNumber:(NSInteger) numberOfFocusetView {
172+
for (int i = 0; i < self.internalViewControllers.count; i++) {
173+
CGFloat originXForView = self.spaceHorizontal + (self.childVCSize.width + self.sizeBetweenVC) * (i - numberOfFocusetView);
174+
if (i == numberOfFocusetView) {
175+
self.internalViewControllers[i].view.frame = CGRectMake(originXForView, self.spaceVertical + self.OffsetOfHeightCentralVC, self.childVCSize.width, self.childVCSize.height );
176+
} else {
177+
self.internalViewControllers[i].view.frame = CGRectMake(originXForView, self.spaceVertical, self.childVCSize.width, self.childVCSize.height);
178+
}
179+
}
180+
}
181+
182+
@end

0 commit comments

Comments
 (0)