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

MWMiPhoneLandscapePlacePage.mm « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3628d6b0ac024d1444a884c23999d2a40a119cb (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
#import "Common.h"
#import "MWMBasePlacePageView.h"
#import "MWMiPhoneLandscapePlacePage.h"
#import "MWMPlacePage+Animation.h"
#import "MWMPlacePageActionBar.h"
#import "MWMPlacePageViewManager.h"
#import "MWMSpringAnimation.h"

#include "Framework.h"

static CGFloat const kMaximumPlacePageWidth = 360.;
extern CGFloat const kBookmarkCellHeight;

typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState)
{
  MWMiPhoneLandscapePlacePageStateClosed,
  MWMiPhoneLandscapePlacePageStateOpen
};

@interface MWMiPhoneLandscapePlacePage ()

@property (nonatomic) MWMiPhoneLandscapePlacePageState state;
@property (nonatomic) CGPoint targetPoint;
@property (nonatomic) CGFloat panVelocity;

@end

@implementation MWMiPhoneLandscapePlacePage

- (void)configure
{
  [super configure];
  self.anchorImageView.backgroundColor = [UIColor whiteColor];
  self.anchorImageView.image = nil;
  [self configureContentInset];
  [self addPlacePageShadowToView:self.extendedPlacePageView offset:CGSizeMake(2.0, 4.0)];
  [self.extendedPlacePageView addSubview:self.actionBar];
  [self.manager addSubviews:@[self.extendedPlacePageView] withNavigationController:nil];
}

- (void)show
{
  if (self.state == MWMiPhoneLandscapePlacePageStateOpen)
    return;
  CGSize const size = self.extendedPlacePageView.superview.size;
  CGFloat const height = MIN(size.width, size.height);
  CGFloat const offset = MIN(height, kMaximumPlacePageWidth);
  self.extendedPlacePageView.minX = -offset;
  self.actionBar.width = offset;
  self.actionBar.minX = 0.0;
  self.state = MWMiPhoneLandscapePlacePageStateOpen;
}

- (void)hide
{
  if (self.state == MWMiPhoneLandscapePlacePageStateClosed)
    return;
  self.state = MWMiPhoneLandscapePlacePageStateClosed;
}

- (void)configureContentInset
{
  CGFloat const height = self.extendedPlacePageView.height - self.anchorImageView.height;
  CGFloat const actionBarHeight = self.actionBar.height;
  UITableView * featureTable = self.basePlacePageView.featureTable;
  CGFloat const tableContentHeight = featureTable.contentSize.height;
  CGFloat const headerViewHeight = self.basePlacePageView.separatorView.maxY;
  CGFloat const availableTableHeight = height - headerViewHeight - actionBarHeight;
  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;
  }
}

- (void)addBookmark
{
  [super addBookmark];
  [self configureContentInset];
}

- (void)removeBookmark
{
  [super removeBookmark];
  [self configureContentInset];
}

- (void)reloadBookmark
{
  [super reloadBookmark];
  [self configureContentInset];
}

- (void)updateTargetPoint
{
  CGSize const size = UIScreen.mainScreen.bounds.size;
  CGFloat const height = MIN(size.width, size.height);
  CGFloat const offset = MIN(height, kMaximumPlacePageWidth);
  switch (self.state)
  {
    case MWMiPhoneLandscapePlacePageStateClosed:
      self.targetPoint = CGPointMake(-offset / 2., (height + self.topBound) / 2.);
      break;
    case MWMiPhoneLandscapePlacePageStateOpen:
      self.targetPoint = CGPointMake(offset / 2., (height + self.topBound) / 2.);
      break;
  }
}
#pragma mark - Actions

- (IBAction)didPan:(UIPanGestureRecognizer *)sender
{
  UIView * ppv = self.extendedPlacePageView;
  UIView * ppvSuper = ppv.superview;
  ppv.midX = MIN(ppv.midX + [sender translationInView:ppvSuper].x, ppv.width / 2.0);
  [sender setTranslation:CGPointZero inView:ppvSuper];
  [self cancelSpringAnimation];
  UIGestureRecognizerState const state = sender.state;
  if (state == UIGestureRecognizerStateEnded || state == UIGestureRecognizerStateCancelled)
  {
    self.panVelocity = [sender velocityInView:ppvSuper].x;
    self.state = self.panVelocity > 0 ? MWMiPhoneLandscapePlacePageStateOpen : MWMiPhoneLandscapePlacePageStateClosed;
    [self updateTargetPoint];
  }
}

- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight
{
  [super willStartEditingBookmarkTitle:keyboardHeight];
  CGFloat const statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
  MWMBasePlacePageView const * basePlacePageView = self.basePlacePageView;
  UITableView const * tableView = basePlacePageView.featureTable;
  CGFloat const baseViewHeight = basePlacePageView.height;
  CGFloat const tableHeight = tableView.contentSize.height;
  CGFloat const headerViewHeight = baseViewHeight - tableHeight;
  CGFloat const titleOriginY = tableHeight - kBookmarkCellHeight - tableView.contentOffset.y;

  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.basePlacePageView.transform = CGAffineTransformMakeTranslation(0., statusBarHeight - headerViewHeight - titleOriginY);
  }];
}

- (void)willFinishEditingBookmarkTitle:(NSString *)title
{
  [super willFinishEditingBookmarkTitle:title];
  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.basePlacePageView.transform = CGAffineTransformMakeTranslation(0., 0.);
  }];
}

#pragma mark - Properties

- (void)setState:(MWMiPhoneLandscapePlacePageState)state
{
  if (_state == state)
    return;
  _state = state;
  [self updateTargetPoint];
}

- (void)setTopBound:(CGFloat)topBound
{
  super.topBound = topBound;
  CGSize const size = self.extendedPlacePageView.superview.size;
  CGFloat const height = MIN(size.width, size.height);
  CGRect const frame = self.extendedPlacePageView.frame;
  self.extendedPlacePageView.frame = {{frame.origin.x, topBound}, {frame.size.width, height - topBound}};
  self.actionBar.maxY = height - topBound;
  if (self.state == MWMiPhoneLandscapePlacePageStateOpen)
    [self updateTargetPoint];
  [self configureContentInset];
}

- (void)setTargetPoint:(CGPoint)targetPoint
{
  _targetPoint = targetPoint;
  __weak MWMiPhoneLandscapePlacePage * weakSelf = self;
  BOOL const stateClosed = self.state == MWMiPhoneLandscapePlacePageStateClosed;
  if (stateClosed)
    GetFramework().GetBalloonManager().RemovePin();
  self.panRecognizer.enabled = !stateClosed;
  [self startAnimatingPlacePage:self initialVelocity:CGPointMake(self.panVelocity, 0.0) completion:^
  {
    __strong MWMiPhoneLandscapePlacePage * self = weakSelf;
    if (stateClosed)
      [self.manager dismissPlacePage];
  }];
  self.panVelocity = 0.0;
}

@end