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

MWMAddPlaceNavigationBar.mm « Components « Classes « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30aad61feb27115dc4983845b3b14e6d23aca2bf (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
#import "MWMAddPlaceNavigationBar.h"
#import "MWMCommon.h"

#include "Framework.h"

@interface MWMAddPlaceNavigationBar ()

@property(copy, nonatomic) MWMVoidBlock doneBlock;
@property(copy, nonatomic) MWMVoidBlock cancelBlock;

@end

@implementation MWMAddPlaceNavigationBar

+ (void)showInSuperview:(UIView *)superview
             isBusiness:(BOOL)isBusiness
          applyPosition:(BOOL)applyPosition
               position:(m2::PointD const &)position
              doneBlock:(MWMVoidBlock)done
            cancelBlock:(MWMVoidBlock)cancel
{
  MWMAddPlaceNavigationBar * navBar = [[[NSBundle mainBundle] loadNibNamed:self.className owner:nil options:nil] firstObject];
  navBar.width = superview.width;
  navBar.doneBlock = done;
  navBar.cancelBlock = cancel;
  navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  [navBar setNeedsLayout];
  navBar.origin = {0., -navBar.height};
  [superview addSubview:navBar];
  [navBar show:isBusiness applyPosition:applyPosition position:position];
}

- (void)show:(BOOL)enableBounds applyPosition:(BOOL)applyPosition position:(m2::PointD const &)position
{
  auto & f = GetFramework();
  f.EnableChoosePositionMode(true /* enable */, enableBounds, applyPosition, position);
  f.BlockTapEvents(true);

  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.transform = CGAffineTransformMakeTranslation(0., self.height);
  }];
}

- (void)dismissWithBlock:(MWMVoidBlock)block
{
  auto & f = GetFramework();
  f.EnableChoosePositionMode(false /* enable */, false /* enableBounds */, false /* applyPosition */, m2::PointD());
  f.BlockTapEvents(false);

  [UIView animateWithDuration:kDefaultAnimationDuration animations:^
  {
    self.transform = CGAffineTransformMakeTranslation(0., -self.height);
  }
  completion:^(BOOL finished)
  {
    [self removeFromSuperview];
    block();
  }];
}

- (IBAction)doneTap
{
  [self dismissWithBlock:self.doneBlock];
}

- (IBAction)cancelTap
{
  [self dismissWithBlock:self.cancelBlock];
}

- (void)layoutSubviews
{
  if (self.superview)
    self.width = self.superview.width;
  [super layoutSubviews];
}

@end