Skip to content

Commit 5811fa7

Browse files
committed
Code refactoring, presenting views with animation added
1 parent a64b428 commit 5811fa7

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

LoadingViewController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'LoadingViewController'
11-
s.version = '0.1.2'
11+
s.version = '0.1.3'
1212
s.summary = 'LoadingViewController is a component for changing controller views: content -> loading -> content or content -> loading -> error.'
1313

1414
# This description is used to generate tags and improve search results.

LoadingViewController/Classes/LoadingViewController.swift

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class LoadingViewController: UIViewController {
100100
return true
101101
}
102102

103-
func addLoadingView(viewToAdd: UIView) {
103+
func addView(viewToAdd: UIView) {
104104
view.addSubview(viewToAdd)
105105
viewToAdd.translatesAutoresizingMaskIntoConstraints = false
106106
let bindings = ["view": viewToAdd]
@@ -109,34 +109,6 @@ public class LoadingViewController: UIViewController {
109109
view.layoutIfNeeded()
110110
}
111111

112-
func addErrorView(viewToAdd: UIView) {
113-
view.addSubview(viewToAdd)
114-
viewToAdd.translatesAutoresizingMaskIntoConstraints = false
115-
let bindings = ["view": viewToAdd]
116-
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|[view]|", options: [.AlignAllLeading, .AlignAllTrailing], metrics: nil, views: bindings))
117-
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: [.AlignAllTop, .AlignAllBottom], metrics: nil, views: bindings))
118-
view.layoutIfNeeded()
119-
}
120-
121-
/*
122-
- (void)addErrorView:(UIView *)aView
123-
{
124-
[self.view addSubview:aView];
125-
aView.translatesAutoresizingMaskIntoConstraints = NO;
126-
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:
127-
@"|[aView]|" options:NSLayoutFormatAlignAllTrailing |
128-
NSLayoutFormatAlignAllLeading metrics:nil views:
129-
NSDictionaryOfVariableBindings(aView)]];
130-
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:
131-
@"V:[aView]|" options:NSLayoutFormatAlignAllBottom metrics:nil
132-
views:NSDictionaryOfVariableBindings(aView)]];
133-
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:
134-
aView attribute:NSLayoutAttributeTop relatedBy:
135-
NSLayoutRelationEqual toItem:self.topGuideConstraint attribute:
136-
NSLayoutAttributeBottom multiplier:1.0 constant:self.contentInsets.top]];
137-
}
138-
*/
139-
140112
func viewForScreen(contentType: ContentType) -> UIView {
141113
switch contentType {
142114
case .Content:
@@ -155,14 +127,14 @@ public class LoadingViewController: UIViewController {
155127
}
156128

157129
// TODO: add ActionHandler support to handle 'Retry' tap on ErrorViews
158-
public func setVisibleScreen(contentType: ContentType, actionHandler:ActionHandler? = nil) {
130+
public func setVisibleScreen(contentType: ContentType, animated: Bool = true, actionHandler:ActionHandler? = nil) {
159131
if visibleContentType != contentType {
160132
visibleContentType = contentType
161-
setActiveView(viewForScreen(visibleContentType))
133+
setActiveView(viewForScreen(visibleContentType), animated: animated)
162134
}
163135
}
164136

165-
func setActiveView(viewToSet: UIView, animated: Bool = true) {
137+
func setActiveView(viewToSet: UIView, animated: Bool) {
166138
if viewToSet != activeView {
167139
let oldView = activeView ?? nil
168140
activeView = viewToSet
@@ -272,14 +244,7 @@ public class LoadingViewController: UIViewController {
272244
startNextAnimationIfNeeded()
273245
}
274246

275-
switch contentType {
276-
case .Loading:
277-
addLoadingView(toView)
278-
case .Failure:
279-
addErrorView(toView)
280-
default:
281-
break
282-
}
247+
addView(toView)
283248

284249
let theFromView = fromView
285250
let fromViewIsContentView = (theFromView == self.contentView)

0 commit comments

Comments
 (0)