-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoadingScreenViewController.m
82 lines (61 loc) · 3.02 KB
/
LoadingScreenViewController.m
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
//
// LoadingScreenViewController.m
// Socket+Graph
//
// Created by Admin on 15.07.15.
// Copyright (c) 2015 Admin. All rights reserved.
//
#import "LoadingScreenViewController.h"
#import "SocketManager.h"
#import "MainViewController.h"
@interface LoadingScreenViewController ()
@end
@implementation LoadingScreenViewController {
UILabel *_loadingLabel;
UIActivityIndicatorView *_activity;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:SMConnectedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SMProfileRecievedNotification object:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
_loadingLabel = [UILabel new];
_loadingLabel.translatesAutoresizingMaskIntoConstraints = NO;
_loadingLabel.text = @"Connecting";
_loadingLabel.textColor = [UIColor grayColor];
_activity = [UIActivityIndicatorView new];
_activity.translatesAutoresizingMaskIntoConstraints = NO;
[_activity setColor:[UIColor grayColor]];
[_activity startAnimating];
[self.view addSubview:_loadingLabel];
[self.view addSubview:_activity];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_loadingLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_loadingLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activity attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_loadingLabel attribute:NSLayoutAttributeTop multiplier:1 constant:-10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activity attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_loadingLabel attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connected) name:SMConnectedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userInfoRecieved) name:SMProfileRecievedNotification object:nil];
}
#pragma mark - Custom methods
- (void)connected
{
_loadingLabel.text = @"Loading profile";
}
- (void)userInfoRecieved
{
_loadingLabel.text = @"Done!";
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView transitionWithView:self.view.window
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
self.view.window.rootViewController = [MainViewController new];
}
completion:nil];
});
}
@end