forked from truongminhthang/CodeSnippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7B126EF6-C60F-40F1-B4C9-140AC2157038.codesnippet
111 lines (90 loc) · 3.64 KB
/
7B126EF6-C60F-40F1-B4C9-140AC2157038.codesnippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>TopLevel</string>
</array>
<key>IDECodeSnippetContents</key>
<string>class BasePageVC: UIPageViewController, UIPageViewControllerDelegate {
var currentViewController: UIViewController? {
return viewControllers?[0]
}
var index : Int {
guard currentViewController != nil else {
return NSNotFound
}
return modelController.indexOfViewController(currentViewController!)
}
var scrollView: UIScrollView! {
if _scrollView == nil {
for view in self.view.subviews {
if(view is UIScrollView) {
_scrollView = (view as! UIScrollView)
}
}
}
return _scrollView
}
var startViewControllerIndex : Int {
return 0
}
private var _scrollView: UIScrollView? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// Configure the page view controller and add it as a child view controller.
delegate = self
dataSource = modelController
if let startingViewController: UIViewController = self.modelController.viewControllerAtIndex(startViewControllerIndex) {
let viewControllers = [startingViewController]
setViewControllers(viewControllers, direction: .forward, animated: false, completion: {done in })
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var modelController: BaseModelController! {
// Return the model controller object, creating it if necessary.
// In more complex implementations, the model controller may be passed to the view controller.
return nil
}
var _modelController: BaseModelController? = nil
// MARK: - UIPageViewController delegate methods
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
}
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
}
func next() {
jump(toIndex: index + 1)
}
func previous() {
jump(toIndex: index - 1)
}
func jump(toIndex: Int, animated: Bool = true) {
guard toIndex != NSNotFound && toIndex >= 0 else {
return
}
let direction : UIPageViewControllerNavigationDirection = toIndex > index ? .forward : .reverse
if let viewController = modelController.viewControllerAtIndex(toIndex) {
self.setViewControllers([viewController], direction: direction , animated: true, completion: {done in })
}
}
func jumpToOrderTaxi() {
jump(toIndex: 1, animated: false)
}
}</string>
<key>IDECodeSnippetIdentifier</key>
<string>7B126EF6-C60F-40F1-B4C9-140AC2157038</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Swift</string>
<key>IDECodeSnippetTitle</key>
<string>Swift 3: class base PageViewController to display Viewcontrollers</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>