-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainViewController.m
More file actions
156 lines (105 loc) · 4.02 KB
/
Copy pathMainViewController.m
File metadata and controls
156 lines (105 loc) · 4.02 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// MainViewController.m
// Week3
//
// Created by Tom Gurka on 6/18/14.
// Copyright (c) 2014 tom. All rights reserved.
//
#import "MainViewController.h"
@interface MainViewController ()
- (IBAction)newsPan:(UIPanGestureRecognizer *)sender;
@property (weak, nonatomic) IBOutlet UIView *newsView;
@property (weak, nonatomic) IBOutlet UIImageView *accountView;
@property (assign,nonatomic) CGPoint originalCenter;
- (IBAction)pressNews:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIScrollView *horScroll;
@end
@implementation MainViewController
{
float centerY;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
centerY = 0;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//Remember the original center mark
self.originalCenter = CGPointMake(self.newsView.center.x, self.newsView.center.y);
self.accountView.alpha = 0;
self.horScroll.contentSize = CGSizeMake(100000, 507);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)newsPan:(UIPanGestureRecognizer *)sender {
CGPoint offset = [sender translationInView:self.view];
if (sender.state == UIGestureRecognizerStateBegan) {
centerY = self.newsView.center.y;
}
else if (sender.state == UIGestureRecognizerStateChanged && self.newsView.center.y < 284){
NSLog(@"%f", self.newsView.center.y);
self.newsView.center = CGPointMake(self.newsView.center.x, centerY + offset.y * .1);
// Hide Settings View
self.accountView.alpha = 0;
}
else if (sender.state == UIGestureRecognizerStateChanged){
//Move the view around
self.newsView.center = CGPointMake(self.newsView.center.x, centerY + offset.y * .9);
//Show View
[UIView animateWithDuration:0.4 animations:^{
self.accountView.alpha = 1;
} completion:nil];
}
else if (sender.state == UIGestureRecognizerStateEnded && self.newsView.center.y < 500){
// News View to Origin
[UIView animateWithDuration:0.4 animations:^
{
self.newsView.center = CGPointMake(self.newsView.center.x, self.originalCenter.y);} completion:nil];
}
// Animate Down
else if (sender.state == UIGestureRecognizerStateEnded && self.newsView.center.y >501)
{
//Show Settings View
[UIView animateWithDuration:0.4 animations:^{
self.accountView.alpha = 1;
} completion:nil];
//Push View Down
[UIView animateWithDuration:0.4 animations:^{
self.newsView.center = CGPointMake(self.newsView.center.x, 805);
} completion:nil];
}
// Animate Up
else if (sender.state == UIGestureRecognizerStateEnded && self.newsView.center.y > 500)
{
// News View to Origin
[UIView animateWithDuration:0.4 animations:^{
self.newsView.center = CGPointMake(self.newsView.center.x, self.originalCenter.y);
} completion:nil];
// Hide Settings View
[UIView animateWithDuration:0.2 animations:^{
self.accountView.alpha = 0;
} completion:nil];
}
}
- (IBAction)pressNews:(UIButton *)sender {
if (self.newsView.center.y >= 805)
// News View to Origin
[UIView animateWithDuration:0.3 animations:^
{
self.newsView.center = CGPointMake(self.newsView.center.x, self.originalCenter.y);} completion:nil];
// Hide Settings View
[UIView animateWithDuration:0.3 animations:^{
self.accountView.alpha = 0;
} completion:nil];
}
@end