Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MWMiPadPlacePage.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: db8d148c0af08ed0527ee378deb1ab53d1c7a352 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#import "Common.h"
#import "MWMiPadPlacePage.h"
#import "MWMPlacePageViewManager.h"
#import "MWMPlacePageActionBar.h"
#import "MWMBasePlacePageView.h"
#import "MWMBookmarkColorViewController.h"
#import "SelectSetVC.h"
#import "UIViewController+Navigation.h"
#import "MWMBookmarkDescriptionViewController.h"
#import "ViewController.h"

extern CGFloat kBookmarkCellHeight;
static CGFloat const kLeftOffset = 12.;
static CGFloat const kTopOffset = 36.;
static CGFloat const kBottomOffset = 12.;

@interface MWMiPadPlacePageViewController : ViewController

@end

@implementation MWMiPadPlacePageViewController

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  [self.navigationController setNavigationBarHidden:YES];
  self.view.autoresizingMask = UIViewAutoresizingNone;
}

@end

@interface MWMiPadNavigationController : UINavigationController

@end

@implementation MWMiPadNavigationController

- (instancetype)initWithViews:(NSArray *)views
{
  MWMiPadPlacePageViewController * viewController = [[MWMiPadPlacePageViewController alloc] init];
  if (!viewController)
    return nil;
  [views enumerateObjectsUsingBlock:^(UIView * view, NSUInteger idx, BOOL *stop)
  {
    [viewController.view addSubview:view];
  }];
  self = [super initWithRootViewController:viewController];
  if (!self)
    return nil;
  [self setNavigationBarHidden:YES];
  [self.navigationBar setTranslucent:NO];
  self.view.autoresizingMask = UIViewAutoresizingNone;
  return self;
}

- (void)backTap:(id)sender
{
  [self popViewControllerAnimated:YES];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
  viewController.view.frame = self.view.bounds;
  [super pushViewController:viewController animated:animated];
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
  NSUInteger const count = self.viewControllers.count;
  CGFloat const height = count > 1 ? ((UIViewController *)self.viewControllers[count - 2]).view.height : 0.0;

  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.view.height = height;
  }
  completion:^(BOOL finished)
  {
    [super popViewControllerAnimated:animated];
  }];
  return self.viewControllers.lastObject;
}

@end

@interface MWMiPadPlacePage ()

@property (nonatomic) MWMiPadNavigationController * navigationController;
@property (nonatomic) CGFloat height;

@end

@implementation MWMiPadPlacePage

- (void)configure
{
  [super configure];

  CGFloat const defaultWidth = 360.;
  [self updatePlacePageLayout];
  [self addPlacePageShadowToView:self.navigationController.view offset:CGSizeMake(0.0, -2.0)];

  [self.manager addSubviews:@[self.navigationController.view] withNavigationController:self.navigationController];
  self.navigationController.view.frame = CGRectMake( -defaultWidth, self.topBound + kTopOffset, defaultWidth, self.height);
  self.extendedPlacePageView.frame = CGRectMake(0., 0., defaultWidth, self.height);
  self.anchorImageView.image = nil;
  self.anchorImageView.backgroundColor = [UIColor whiteColor];
  self.actionBar.width = defaultWidth;
  [self configureContentInset];
}

- (void)show
{
  UIView * view = self.navigationController.view;
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    view.minY = self.topBound + kTopOffset;
    view.minX = self.leftBound + kLeftOffset;
    view.alpha = 1.0;
  }];
}

- (void)hide
{
  [self.manager dismissPlacePage];
}

- (void)dismiss
{
  UIView * view = self.navigationController.view;
  UIViewController * controller = self.navigationController;
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    view.maxX = 0.0;
    view.alpha = 0.0;
  }
  completion:^(BOOL finished)
  {
    [view removeFromSuperview];
    [controller removeFromParentViewController];
    [super dismiss];
  }];
}

- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight
{
  [super willStartEditingBookmarkTitle:keyboardHeight];
  [self updatePlacePagePosition];
}

- (void)willFinishEditingBookmarkTitle:(NSString *)title
{
  [super willFinishEditingBookmarkTitle:title];
  [self updatePlacePageLayout];
}

- (void)addBookmark
{
  [super addBookmark];
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    [self updatePlacePageLayout];
  }];
}

- (void)removeBookmark
{
  [super removeBookmark];
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    [self updatePlacePageLayout];
  }];
}

- (void)changeBookmarkColor
{
  MWMBookmarkColorViewController * controller = [[MWMBookmarkColorViewController alloc] initWithNibName:[MWMBookmarkColorViewController className] bundle:nil];
  controller.iPadOwnerNavigationController = self.navigationController;
  controller.placePageManager = self.manager;
  [self.navigationController pushViewController:controller animated:YES];
}

- (void)changeBookmarkCategory
{
  SelectSetVC * controller = [[SelectSetVC alloc] initWithPlacePageManager:self.manager];
  controller.iPadOwnerNavigationController = self.navigationController;
  [self.navigationController pushViewController:controller animated:YES];
}

- (void)changeBookmarkDescription
{
  MWMBookmarkDescriptionViewController * controller = [[MWMBookmarkDescriptionViewController alloc] initWithPlacePageManager:self.manager];
  controller.iPadOwnerNavigationController = self.navigationController;
  [self.navigationController pushViewController:controller animated:YES];
}

- (IBAction)didPan:(UIPanGestureRecognizer *)sender
{
  UIView * view = self.navigationController.view;
  UIView * superview = view.superview;

  CGFloat const leftOffset = self.leftBound + kLeftOffset;
  view.minX += [sender translationInView:superview].x;
  view.minX = MIN(view.minX, leftOffset);
  [sender setTranslation:CGPointZero inView:superview];

  CGFloat const alpha = MAX(0.0, view.maxX) / (view.width + leftOffset);
  view.alpha = alpha;
  UIGestureRecognizerState const state = sender.state;
  if (state == UIGestureRecognizerStateEnded || state == UIGestureRecognizerStateCancelled)
  {
    if (alpha < 0.8)
      [self.manager dismissPlacePage];
    else
      [self show];
  }
}

- (void)updatePlacePageLayout
{
  CGFloat const actionBarHeight = self.actionBar.height;
  self.height = self.basePlacePageView.height + self.anchorImageView.height + actionBarHeight - 1;
  self.actionBar.origin = CGPointMake(0., self.height - actionBarHeight);
  [self updatePlacePagePosition];
}

- (void)updatePlacePagePosition
{
  UIView * view = self.navigationController.view;
  view.minY = MIN([self getAvailableHeight] + kTopOffset - view.height, self.topBound + kTopOffset);
  [self configureContentInset];
}

- (void)configureContentInset
{
  UITableView * featureTable = self.basePlacePageView.featureTable;
  CGFloat const height = self.navigationController.view.height;
  CGFloat const tableContentHeight = featureTable.contentSize.height;
  CGFloat const headerViewHeight = self.basePlacePageView.separatorView.maxY;
  CGFloat const availableTableHeight = height - headerViewHeight - self.actionBar.height;
  CGFloat const externalHeight = tableContentHeight - availableTableHeight;
  if (externalHeight > 0.)
  {
    featureTable.contentInset = UIEdgeInsetsMake(0., 0., externalHeight, 0.);
    featureTable.scrollEnabled = YES;
  }
  else
  {
    [featureTable setContentOffset:CGPointZero animated:YES];
    featureTable.scrollEnabled = NO;
  }
}

- (CGFloat)getAvailableHeight
{
  return self.parentViewHeight - self.keyboardHeight - kTopOffset - kBottomOffset;
}

#pragma mark - Properties

- (void)setHeight:(CGFloat)height
{
  _height = MIN(height, [self getAvailableHeight]);
  self.navigationController.view.height = _height;
  self.extendedPlacePageView.height = _height;
}

- (MWMiPadNavigationController *)navigationController
{
  if (!_navigationController)
  {
    _navigationController = [[MWMiPadNavigationController alloc] initWithViews:@[self.extendedPlacePageView, self.actionBar]];
  }
  return _navigationController;
}

- (void)setTopBound:(CGFloat)topBound
{
  super.topBound = topBound;
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.navigationController.view.minY = topBound + kTopOffset;
  }];
}

- (void)setLeftBound:(CGFloat)leftBound
{
  super.leftBound = leftBound;
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.navigationController.view.minX = leftBound + kLeftOffset;
  }];
}
@end