[ios] Move zoom buttons.

This commit is contained in:
Ilya Grechuhin 2015-05-29 15:28:16 +03:00 committed by Alex Zolotarev
parent dabc7d0665
commit cf600dfd9b
12 changed files with 122 additions and 7 deletions

View file

@ -8,6 +8,13 @@
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, MWMMapViewControlsButton)
{
MWMMapViewControlsButtonZoom,
MWMMapViewControlsButtonMenu,
MWMMapViewControlsButtonLocation
};
@class MapViewController;
@interface MWMMapViewControlsManager : NSObject
@ -19,5 +26,7 @@
- (instancetype)initWithParentController:(MapViewController *)controller;
- (void)resetZoomButtonsVisibility;
- (void)moveButton:(MWMMapViewControlsButton)button toDefaultPosition:(BOOL)defaultPosition;
- (void)setBottomBound:(CGFloat)bound;
@end

View file

@ -42,6 +42,23 @@
[self.zoomButtons resetVisibility];
}
- (void)moveButton:(MWMMapViewControlsButton)button toDefaultPosition:(BOOL)defaultPosition
{
switch (button)
{
case MWMMapViewControlsButtonZoom:
[self.zoomButtons moveToDefaultPosition:defaultPosition];
break;
default:
break;
}
}
- (void)setBottomBound:(CGFloat)bound
{
[self.zoomButtons setBottomBound:bound];
}
#pragma mark - Properties
- (void)setHidden:(BOOL)hidden

View file

@ -7,6 +7,7 @@
//
static NSTimeInterval const kMenuViewHideFramesCount = 7.0;
static NSTimeInterval const kMenuViewMoveFramesCount = 7.0;
static inline NSTimeInterval framesDuration(NSTimeInterval const framesCount)
{

View file

@ -14,5 +14,7 @@
- (instancetype)initWithParentView:(UIView *)view;
- (void)resetVisibility;
- (void)moveToDefaultPosition:(BOOL)defaultPosition;
- (void)setBottomBound:(CGFloat)bound;
@end

View file

@ -51,6 +51,16 @@ extern NSString * const kAlohalyticsTapEventKey;
self.zoomView.hidden = !zoomButtonsEnabled;
}
- (void)moveToDefaultPosition:(BOOL)defaultPosition
{
self.zoomView.defaultPosition = defaultPosition;
}
- (void)setBottomBound:(CGFloat)bound
{
self.zoomView.bottomBound = bound;
}
- (void)zoom:(CGFloat)scale
{
GetFramework().Scale(scale);

View file

@ -10,6 +10,9 @@
@interface MWMZoomButtonsView : UIView
@property (nonatomic) BOOL defaultPosition;
@property (nonatomic) CGFloat bottomBound;
- (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available")));
- (instancetype)init __attribute__((unavailable("init is not available")));

View file

@ -10,8 +10,11 @@
#import "MWMMapViewControlsCommon.h"
#import "UIKitCategories.h"
static CGFloat const kZoomViewOffsetToTopBound = 12.0;
static CGFloat const kZoomViewOffsetToBottomBound = 294.0;
static CGFloat const kZoomViewOffsetToTopBoundDefault = 12.0;
static CGFloat const kZoomViewOffsetToTopBoundMoved = 66.0;
static CGFloat const kZoomViewOffsetToBottomBound = 40.0;
static CGFloat const kZoomViewOffsetToFrameBound = 294.0;
static CGFloat const kZoomViewHideBoundPercent = 0.4;
@interface MWMZoomButtonsView()
@ -28,6 +31,8 @@ static CGFloat const kZoomViewOffsetToBottomBound = 294.0;
{
self.defaultBounds = self.bounds;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.defaultPosition = YES;
self.bottomBound = 0.0;
}
return self;
}
@ -37,8 +42,7 @@ static CGFloat const kZoomViewOffsetToBottomBound = 294.0;
[super layoutSubviews];
self.bounds = self.defaultBounds;
[self layoutXPosition:self.hidden];
self.maxY = self.superview.height - kZoomViewOffsetToBottomBound;
self.minY = MAX(self.minY, kZoomViewOffsetToTopBound);
[self layoutYPosition:self.defaultPosition];
}
- (void)layoutXPosition:(BOOL)hidden
@ -49,10 +53,37 @@ static CGFloat const kZoomViewOffsetToBottomBound = 294.0;
self.maxX = self.superview.width - kViewControlsOffsetToBounds;
}
- (void)layoutYPosition:(BOOL)defaultPosition
{
if (self.bottomBound > 0.0)
self.maxY = self.bottomBound - kZoomViewOffsetToBottomBound;
else
self.maxY = self.superview.height - kZoomViewOffsetToFrameBound;
self.minY = MAX(self.minY, defaultPosition ? kZoomViewOffsetToTopBoundDefault : kZoomViewOffsetToTopBoundMoved);
}
- (void)moveAnimated
{
[UIView animateWithDuration:framesDuration(kMenuViewMoveFramesCount) animations:^
{
[self layoutYPosition:self.defaultPosition];
}];
}
- (void)fadeAnimatedIn:(BOOL)show
{
[UIView animateWithDuration:framesDuration(kMenuViewHideFramesCount) animations:^
{
self.alpha = show ? 1.0 : 0.0;
}];
}
#pragma mark - Properties
- (void)setHidden:(BOOL)hidden
{
if (super.hidden == hidden)
return;
if (!hidden)
super.hidden = NO;
[self layoutXPosition:!hidden];
@ -67,4 +98,30 @@ static CGFloat const kZoomViewOffsetToBottomBound = 294.0;
}];
}
- (void)setDefaultPosition:(BOOL)defaultPosition
{
_defaultPosition = defaultPosition;
[self moveAnimated];
}
- (void)setBottomBound:(CGFloat)bottomBound
{
CGFloat const hideBound = kZoomViewHideBoundPercent * self.superview.height;
BOOL const isHidden = _bottomBound < hideBound;
BOOL const willHide = bottomBound < hideBound;
_bottomBound = bottomBound;
if (willHide)
{
if (!isHidden)
[self fadeAnimatedIn:NO];
}
else
{
[self moveAnimated];
if (isHidden)
[self fadeAnimatedIn:YES];
}
}
@end

View file

@ -560,15 +560,15 @@ extern NSString * const kAlohalyticsTapEventKey = @"$onClick";
[super viewDidLoad];
self.view.clipsToBounds = YES;
self.controlsManager = [[MWMMapViewControlsManager alloc] initWithParentController:self];
[self.view addSubview:self.routeViewWrapper];
[self.view addSubview:self.searchView];
[self.view addSubview:self.containerView];
self.controlsManager = [[MWMMapViewControlsManager alloc] initWithParentController:self];
[self showRoutingFeatureDialog];
}
@ -914,6 +914,11 @@ extern NSString * const kAlohalyticsTapEventKey = @"$onClick";
[self dismissRouting];
}
- (void)routeViewWillEnterState:(RouteViewState)state
{
[self.controlsManager moveButton:MWMMapViewControlsButtonZoom toDefaultPosition:(state == RouteViewStateHidden)];
}
- (void)dismissRouting
{
GetFramework().CloseRouting();
@ -990,6 +995,11 @@ extern NSString * const kAlohalyticsTapEventKey = @"$onClick";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
- (void)placePageViewWillEnterState:(PlacePageState)state
{
[self.controlsManager moveButton:MWMMapViewControlsButtonZoom toDefaultPosition:(state == PlacePageStateHidden)];
}
#pragma mark - UIKitViews delegates
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

View file

@ -21,6 +21,8 @@ typedef NS_ENUM(NSUInteger, PlacePageState) {
- (void)placePageViewDidStartRouting:(PlacePageView *)placePage;
- (void)placePageViewWillEnterState:(PlacePageState)state;
@end

View file

@ -424,6 +424,7 @@ typedef NS_ENUM(NSUInteger, CellRow)
- (void)applyState:(PlacePageState)state animated:(BOOL)animated
{
[self.delegate placePageViewWillEnterState:state];
_state = state;
[self updateBookmarkStateAnimated:NO];
[self updateBookmarkViewsAlpha:animated];

View file

@ -14,6 +14,8 @@ typedef NS_ENUM(NSUInteger, RouteViewState) {
- (void)routeViewDidCancelRouting:(RouteView *)routeView;
- (void)routeViewDidStartFollowing:(RouteView *)routeView;
- (void)routeViewWillEnterState:(RouteViewState)state;
@end
@interface RouteView : UIView

View file

@ -151,6 +151,7 @@ extern NSString * const kAlohalyticsTapEventKey;
- (void)setState:(RouteViewState)state animated:(BOOL)animated
{
[self.delegate routeViewWillEnterState:state];
_state = state;
[UIView animateWithDuration:(animated ? 0.5 : 0) delay:0 damping:0.83 initialVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^ {