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
|
//
// MWMPlacePageNavigationBar.m
// Maps
//
// Created by v.mikhaylenko on 13.05.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
#import "MWMPlacePageNavigationBar.h"
#import "MWMiPhonePortraitPlacePage.h"
#import "MWMPlacePageViewManager.h"
#import "MWMBasePlacePageView.h"
#import "UIKitCategories.h"
#import "MWMPlacePageEntity.h"
#import <objc/runtime.h>
static NSString * const kPlacePageNavigationBarNibName = @"PlacePageNavigationBar";
static CGFloat const kNavigationBarHeight = 64.;
static inline CGPoint const openCenter(CGFloat xPosition)
{
return CGPointMake(xPosition, kNavigationBarHeight / 2.);
}
static inline CGPoint const dismissCenter(CGFloat xPosition)
{
return CGPointMake(xPosition, - kNavigationBarHeight / 2.);
}
@interface MWMPlacePageNavigationBar ()
@property (weak, nonatomic) IBOutlet UILabel * titleLabel;
@property (weak, nonatomic) MWMiPhonePortraitPlacePage * placePage;
@end
@implementation MWMPlacePageNavigationBar
+ (void)remove
{
UIScreen * screen = [UIScreen mainScreen];
MWMPlacePageNavigationBar * navBar = objc_getAssociatedObject(screen, @selector(navigationBarWithPlacePage:));
if (!navBar)
return;
[navBar removeFromSuperview];
objc_setAssociatedObject(screen, @selector(navigationBarWithPlacePage:), nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
+ (void)showNavigationBarForPlacePage:(MWMiPhonePortraitPlacePage *)placePage
{
UIView const * superview = placePage.manager.ownerViewController.view;
UIScreen * screen = [UIScreen mainScreen];
MWMPlacePageNavigationBar * navBar = objc_getAssociatedObject(screen, @selector(navigationBarWithPlacePage:));
if (!navBar)
{
navBar = [self navigationBarWithPlacePage:placePage];
objc_setAssociatedObject(screen, @selector(navigationBarWithPlacePage:), navBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[superview addSubview:navBar];
}
navBar.placePage = placePage;
MWMPlacePageEntity * entity = placePage.manager.entity;
navBar.titleLabel.text = entity.type == MWMPlacePageEntityTypeBookmark ? entity.bookmarkTitle : entity.title;
[navBar show];
}
+ (void)dismissNavigationBar
{
UIScreen * screen = [UIScreen mainScreen];
MWMPlacePageNavigationBar * navBar = objc_getAssociatedObject(screen, @selector(navigationBarWithPlacePage:));
if (!navBar)
return;
[navBar dismiss];
}
- (void)dismiss
{
[UIView animateWithDuration:.1 animations:^
{
self.center = dismissCenter(self.center.x);
}];
}
- (void)show
{
[UIView animateWithDuration:.1 animations:^
{
self.center = openCenter(self.center.x);
}];
}
+ (instancetype)navigationBarWithPlacePage:(MWMiPhonePortraitPlacePage *)placePage
{
MWMPlacePageNavigationBar * navBar = [[[NSBundle mainBundle] loadNibNamed:kPlacePageNavigationBarNibName owner:nil options:nil] firstObject];
navBar.placePage = placePage;
navBar.autoresizingMask = UIViewAutoresizingNone;
UIView const * superview = placePage.manager.ownerViewController.view;
navBar.center = dismissCenter(superview.center.x);
CGSize const size = [[UIScreen mainScreen] bounds].size;
BOOL const isLandscape = size.width > size.height;
CGFloat const width = isLandscape ? size.height : size.width;
navBar.width = width;
return navBar;
}
- (IBAction)backTap:(id)sender
{
[self dismiss];
[self.placePage.manager refreshPlacePage];
}
- (void)layoutSubviews
{
if (self)
self.origin = CGPointZero;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Prevent super call to stop event propagation
// [super touchesBegan:touches withEvent:event];
}
@end
|