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

MWMPPView.mm « PlacePageView « PlacePageLayout « PlacePage « UI « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ae000aaa09c51692b22ced6764869a2b8ae8e10 (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
#import "MWMPPView.h"
#import "MWMCommon.h"
#import "MWMPlacePageActionBar.h"
#import "SwiftBridge.h"

namespace
{
// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVOBasics.html
void * kContext = &kContext;
NSString * const kTableViewContentSizeKeyPath = @"contentSize";
CGFloat const kTableViewTopInset = -36;

}  // namespace

#pragma mark - MWMPPScrollView

@implementation MWMPPScrollView

- (instancetype)initWithFrame:(CGRect)frame inactiveView:(UIView *)inactiveView
{
  self = [super initWithFrame:frame];
  if (self)
  {
    self.decelerationRate = UIScrollViewDecelerationRateFast;
    self.showsVerticalScrollIndicator = NO;
    _inactiveView = inactiveView;
  }
  return self;
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
  UIView * v = self.inactiveView;
  return point.y > [self convertRect:v.bounds fromView:v].origin.y;
}

@end

#pragma mark - MWMPPView

@implementation MWMPPView

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
  if (context == kContext)
  {
    NSValue * s = change[@"new"];
    CGFloat const height = s.CGSizeValue.height;
    if (!equalScreenDimensions(height, self.currentContentHeight) && !self.tableView.scrollEnabled)
    {
      self.currentContentHeight = height;
      self.height = height + self.top.height;
      [self setNeedsLayout];
      [self.delegate updateWithHeight:self.height];
    }
    return;
  }

  [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}

- (void)awakeFromNib
{
  [super awakeFromNib];
  [self.tableView addObserver:self
                   forKeyPath:kTableViewContentSizeKeyPath
                      options:NSKeyValueObservingOptionNew
                      context:kContext];

  self.tableView.estimatedRowHeight = 44.;
  self.tableView.rowHeight = UITableViewAutomaticDimension;
  self.tableView.contentInset = {.top = kTableViewTopInset, .bottom = - kTableViewTopInset};
  if (IPAD)
    self.autoresizingMask = UIViewAutoresizingNone;
}

- (void)dealloc
{
  [self.tableView removeObserver:self forKeyPath:kTableViewContentSizeKeyPath context:kContext];
}

- (void)layoutSubviews
{
  [super layoutSubviews];
  if (!IPAD)
    return;

  for (UIView * sv in self.subviews)
  {
    if (![sv isKindOfClass:[MWMPlacePageActionBar class]])
      continue;
    sv.maxY = self.height;
    break;
  }
}

#pragma mark - VisibleArea

- (MWMVisibleAreaAffectDirection)visibleAreaAffectDirection
{
  return IPAD ? MWMVisibleAreaAffectDirectionLeft : MWMVisibleAreaAffectDirectionNone;
}

@end