[ios] Added zoom buttons fade on small space.

This commit is contained in:
Ilya Grechuhin 2015-07-23 13:47:40 +03:00 committed by Alex Zolotarev
parent a78f21056e
commit d15c967af6
17 changed files with 121 additions and 59 deletions

View file

@ -14,9 +14,10 @@
#import "MWMPlacePageViewManager.h"
#import "MWMPlacePageViewManagerDelegate.h"
#import "MWMSideMenuManager.h"
#import "MWMSideMenuManagerDelegate.h"
#import "MWMZoomButtons.h"
@interface MWMMapViewControlsManager () <MWMPlacePageViewManagerDelegate, MWMNavigationDashboardManagerDelegate>
@interface MWMMapViewControlsManager () <MWMPlacePageViewManagerProtocol, MWMNavigationDashboardManagerDelegate, MWMSideMenuManagerProtocol>
@property (nonatomic) MWMZoomButtons * zoomButtons;
@property (nonatomic) MWMLocationButton * locationButton;
@ -42,7 +43,7 @@
self.ownerController = controller;
self.zoomButtons = [[MWMZoomButtons alloc] initWithParentView:controller.view];
self.locationButton = [[MWMLocationButton alloc] initWithParentView:controller.view];
self.menuManager = [[MWMSideMenuManager alloc] initWithParentController:controller];
self.menuManager = [[MWMSideMenuManager alloc] initWithParentController:controller delegate:self];
self.placePageManager = [[MWMPlacePageViewManager alloc] initWithViewController:controller delegate:self];
self.navigationManager = [[MWMNavigationDashboardManager alloc] initWithParentView:controller.view delegate:self];
self.hidden = NO;
@ -76,11 +77,19 @@
[self.placePageManager stopBuildingRoute];
}
#pragma mark - MWMSideMenuManagerProtocol
- (void)sideMenuDidUpdateLayout
{
[self.zoomButtons setBottomBound:self.menuManager.menuButtonFrameWithSpacing.origin.y];
}
#pragma mark - MWMPlacePageViewManagerDelegate
- (void)dragPlacePage:(CGPoint)point
{
[self.zoomButtons setBottomBound:point.y];
CGFloat const bound = MIN(self.menuManager.menuButtonFrameWithSpacing.origin.y, point.y);
[self.zoomButtons setBottomBound:bound];
}
- (void)addPlacePageViews:(NSArray *)views
@ -112,8 +121,11 @@
- (void)navigationDashBoardDidUpdate
{
CGFloat const topBound = self.topBound + self.navigationManager.height;
[self.zoomButtons setTopBound:topBound];
[self.placePageManager setTopBound:topBound];
[UIView animateWithDuration:0.2 animations:^
{
[self.zoomButtons setTopBound:topBound];
[self.placePageManager setTopBound:topBound];
}];
}
#pragma mark - Properties

View file

@ -9,11 +9,11 @@
#import "MWMSideMenuButtonDelegate.h"
#import "MWMSideMenuDelegate.h"
#import "MWMSideMenuDownloadBadge.h"
#import <UIKit/UIKit.h>
@interface MWMSideMenuButton : UIView <MWMSideMenuDownloadBadgeOwner>
@property (weak, nonatomic) id<MWMSideMenuInformationDisplayProtocol, MWMSideMenuTapProtocol> delegate;
@property (nonatomic, readonly) CGRect frameWithSpacing;
@property (weak, nonatomic) id<MWMSideMenuInformationDisplayProtocol, MWMSideMenuButtonTapProtocol, MWMSideMenuButtonLayoutProtocol> delegate;
@property (weak, nonatomic) MWMSideMenuDownloadBadge * downloadBadge;
- (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("initWithFrame is not available")));

View file

@ -58,6 +58,7 @@
self.buttonImage.frame = self.bounds = self.defaultBounds;
self.maxY = self.superview.height - 2.0 * kViewControlsOffsetToBounds;
[self layoutXPosition:self.hidden];
[self.delegate menuButtonDidUpdateLayout];
}
- (void)layoutXPosition:(BOOL)hidden
@ -141,4 +142,10 @@
[self addSubview:downloadBadge];
}
- (CGRect)frameWithSpacing
{
CGFloat const outset = 2.0 * kViewControlsOffsetToBounds;
return CGRectInset(self.frame, -outset, -outset);
}
@end

View file

@ -6,9 +6,15 @@
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
@protocol MWMSideMenuTapProtocol <NSObject>
@protocol MWMSideMenuButtonTapProtocol <NSObject>
- (void)handleSingleTap;
- (void)handleDoubleTap;
@end
@protocol MWMSideMenuButtonLayoutProtocol <NSObject>
- (void)menuButtonDidUpdateLayout;
@end

View file

@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
@class MapViewController;
@protocol MWMSideMenuManagerProtocol;
typedef NS_ENUM(NSUInteger, MWMSideMenuState)
{
@ -20,8 +21,9 @@ typedef NS_ENUM(NSUInteger, MWMSideMenuState)
@interface MWMSideMenuManager : NSObject
@property (nonatomic) MWMSideMenuState state;
@property (nonatomic, readonly) CGRect menuButtonFrameWithSpacing;
- (instancetype)init __attribute__((unavailable("init is not available")));
- (instancetype)initWithParentController:(MapViewController *)controller;
- (instancetype)initWithParentController:(MapViewController *)controller delegate:(id<MWMSideMenuManagerProtocol>)delegate;
@end

View file

@ -18,6 +18,7 @@
#import "MWMSideMenuDelegate.h"
#import "MWMSideMenuDownloadBadge.h"
#import "MWMSideMenuManager.h"
#import "MWMSideMenuManagerDelegate.h"
#import "MWMSideMenuView.h"
#import "SettingsAndMoreVC.h"
#import "ShareActionSheet.h"
@ -30,23 +31,26 @@ static NSString * const kMWMSideMenuViewsNibName = @"MWMSideMenuViews";
extern NSString * const kAlohalyticsTapEventKey;
@interface MWMSideMenuManager() <MWMSideMenuInformationDisplayProtocol, MWMSideMenuTapProtocol>
@interface MWMSideMenuManager() <MWMSideMenuInformationDisplayProtocol, MWMSideMenuButtonTapProtocol, MWMSideMenuButtonLayoutProtocol>
@property (weak, nonatomic) id<MWMSideMenuManagerProtocol> delegate;
@property (weak, nonatomic) MapViewController * controller;
@property (nonatomic) IBOutlet MWMSideMenuButton * menuButton;
@property (nonatomic) IBOutlet MWMSideMenuView * sideMenu;
@property (nonatomic) IBOutlet MWMSideMenuDownloadBadge * downloadBadge;
@property (nonatomic) IBOutlet MWMSideMenuView * sideMenu;
@end
@implementation MWMSideMenuManager
- (instancetype)initWithParentController:(MapViewController *)controller
- (instancetype)initWithParentController:(MapViewController *)controller delegate:(id<MWMSideMenuManagerProtocol>)delegate
{
self = [super init];
if (self)
{
self.controller = controller;
self.delegate = delegate;
[[NSBundle mainBundle] loadNibNamed:kMWMSideMenuViewsNibName owner:self options:nil];
[self.controller.view addSubview:self.menuButton];
[self.menuButton setup];
@ -116,6 +120,8 @@ extern NSString * const kAlohalyticsTapEventKey;
self.state = MWMSideMenuStateActive;
}
#pragma mark - MWMSideMenuButtonTapProtocol
- (void)handleSingleTap
{
[self toggleMenu];
@ -126,6 +132,13 @@ extern NSString * const kAlohalyticsTapEventKey;
[self menuActionOpenSearch];
}
#pragma mark - MWMSideMenuButtonLayoutProtocol
- (void)menuButtonDidUpdateLayout
{
[self.delegate sideMenuDidUpdateLayout];
}
#pragma mark - MWMSideMenuInformationDisplayProtocol
- (void)setRulerPivot:(m2::PointD)pivot
@ -222,4 +235,9 @@ extern NSString * const kAlohalyticsTapEventKey;
[self.controller updateStatusBarStyle];
}
- (CGRect)menuButtonFrameWithSpacing
{
return self.menuButton.frameWithSpacing;
}
@end

View file

@ -0,0 +1,13 @@
//
// MWMSideMenuManagerDelegate.h
// Maps
//
// Created by Ilya Grechuhin on 23.07.15.
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
@protocol MWMSideMenuManagerProtocol <NSObject>
- (void)sideMenuDidUpdateLayout;
@end

View file

@ -54,29 +54,38 @@ static CGFloat const kZoomViewHideBoundPercent = 0.4;
- (void)layoutYPosition
{
self.maxY = self.superview.height - kZoomViewOffsetToFrameBound;
if (self.bottomBound > 0.0)
self.maxY = MIN(self.maxY, self.bottomBound - kZoomViewOffsetToBottomBound);
self.minY = MAX(self.minY, self.topBound + kZoomViewOffsetToTopBound);
CGFloat const maxY = MIN(self.superview.height - kZoomViewOffsetToFrameBound, self.bottomBound - kZoomViewOffsetToBottomBound);
self.minY = MAX(maxY - self.height, self.topBound + kZoomViewOffsetToTopBound);
}
- (void)moveAnimated
{
if (self.hidden)
return;
[UIView animateWithDuration:framesDuration(kMenuViewMoveFramesCount) animations:^
{
[self layoutYPosition];
}];
[UIView animateWithDuration:framesDuration(kMenuViewMoveFramesCount) animations:^{ [self layoutYPosition]; }];
}
- (void)fadeAnimatedIn:(BOOL)show
{
[UIView animateWithDuration:framesDuration(kMenuViewHideFramesCount) animations:^
[UIView animateWithDuration:framesDuration(kMenuViewHideFramesCount) animations:^{ self.alpha = show ? 1.0 : 0.0; }];
}
- (void)animate
{
CGFloat const hideBound = kZoomViewHideBoundPercent * self.superview.height;
BOOL const isHidden = self.alpha == 0.0;
BOOL const willHide = (self.bottomBound < hideBound) || (self.defaultBounds.size.height > self.bottomBound - self.topBound);
if (willHide)
{
self.alpha = show ? 1.0 : 0.0;
}];
if (!isHidden)
[self fadeAnimatedIn:NO];
}
else
{
[self moveAnimated];
if (isHidden)
[self fadeAnimatedIn:YES];
}
}
#pragma mark - Properties
@ -107,28 +116,18 @@ static CGFloat const kZoomViewHideBoundPercent = 0.4;
- (void)setTopBound:(CGFloat)topBound
{
if (_topBound == topBound)
return;
_topBound = topBound;
[self moveAnimated];
[self animate];
}
- (void)setBottomBound:(CGFloat)bottomBound
{
CGFloat const hideBound = kZoomViewHideBoundPercent * self.superview.height;
BOOL const isHidden = _bottomBound < hideBound;
BOOL const willHide = bottomBound < hideBound;
if (_bottomBound == bottomBound)
return;
_bottomBound = bottomBound;
if (willHide)
{
if (!isHidden)
[self fadeAnimatedIn:NO];
}
else
{
[self moveAnimated];
if (isHidden)
[self fadeAnimatedIn:YES];
}
[self animate];
}
@end

View file

@ -8,6 +8,8 @@
#import "MWMNavigationView.h"
static CGFloat const kStatusbarHeight = 20.0;
@interface MWMNavigationView ()
@property (nonatomic) BOOL isVisible;
@ -33,7 +35,7 @@
{
[superview insertSubview:self atIndex:0];
self.frame = self.defaultFrame;
self.isVisible = YES;
dispatch_async(dispatch_get_main_queue(), ^{ self.isVisible = YES; });
}
- (void)remove
@ -45,8 +47,11 @@
{
[UIView animateWithDuration:0.2 animations:^
{
self.frame = self.defaultFrame;
[self layoutStatusbar];
if (!CGRectEqualToRect(self.frame, self.defaultFrame))
{
self.frame = self.defaultFrame;
[self layoutStatusbar];
}
}
completion:^(BOOL finished)
{
@ -58,13 +63,11 @@
- (void)layoutStatusbar
{
CGRect const statusBarFrame = UIApplication.sharedApplication.statusBarFrame;
if (self.topBound <= statusBarFrame.size.height)
if (self.topBound <= kStatusbarHeight)
{
if (![self.statusbarBackground.superview isEqual:self])
[self addSubview:self.statusbarBackground];
self.statusbarBackground.frame = statusBarFrame;
self.statusbarBackground.maxY = 0.0;
self.statusbarBackground.frame = CGRectMake(0.0, -kStatusbarHeight, self.width, kStatusbarHeight);
}
else
{
@ -81,7 +84,7 @@
- (void)setTopBound:(CGFloat)topBound
{
_topBound = MAX(topBound, UIApplication.sharedApplication.statusBarFrame.size.height);
_topBound = MAX(topBound, kStatusbarHeight);
[self layoutSubviews];
}

View file

@ -39,7 +39,7 @@
- (void)reloadBookmark;
- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight;
- (void)willFinishEditingBookmarkTitle:(NSString *)title;
- (void)addPlacePageShadowToView:(UIView *)view;
- (void)addPlacePageShadowToView:(UIView *)view offset:(CGSize)offset;
- (IBAction)didTap:(UITapGestureRecognizer *)sender;

View file

@ -98,14 +98,14 @@ extern NSString * const kAlohalyticsTapEventKey;
[self.actionBar dismissActivityIndicatior];
}
- (void)addPlacePageShadowToView:(UIView *)view
- (void)addPlacePageShadowToView:(UIView *)view offset:(CGSize)offset
{
CALayer * layer = view.layer;
layer.masksToBounds = NO;
layer.shadowColor = UIColor.blackColor.CGColor;
layer.shadowRadius = 4.;
layer.shadowOpacity = 0.24f;
layer.shadowOffset = CGSizeMake(0., - 2.);
layer.shadowOffset = offset;
layer.shouldRasterize = YES;
layer.rasterizationScale = [[UIScreen mainScreen] scale];
}

View file

@ -11,7 +11,7 @@
#include "map/user_mark.hpp"
@class MWMPlacePageEntity, MWMPlacePageNavigationBar;
@protocol MWMPlacePageViewManagerDelegate;
@protocol MWMPlacePageViewManagerProtocol;
@interface MWMPlacePageViewManager : NSObject
@ -21,7 +21,7 @@
@property (nonatomic) CGFloat topBound;
@property (nonatomic, readonly) BOOL isDirectionViewShown;
- (instancetype)initWithViewController:(UIViewController *)viewController delegate:(id<MWMPlacePageViewManagerDelegate>) delegate;
- (instancetype)initWithViewController:(UIViewController *)viewController delegate:(id<MWMPlacePageViewManagerProtocol>)delegate;
- (void)showPlacePageWithUserMark:(unique_ptr<UserMarkCopy>)userMark;
- (void)refreshPlacePage;
- (void)dismissPlacePage;

View file

@ -36,20 +36,20 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState)
unique_ptr<UserMarkCopy> m_userMark;
}
@property (weak, nonatomic) UIViewController<MWMPlacePageViewManagerDelegate> * ownerViewController;
@property (weak, nonatomic) UIViewController<MWMPlacePageViewManagerProtocol> * ownerViewController;
@property (nonatomic, readwrite) MWMPlacePageEntity * entity;
@property (nonatomic) MWMPlacePage * placePage;
@property (nonatomic) MWMPlacePageManagerState state;
@property (nonatomic) ShareActionSheet * actionSheet;
@property (nonatomic) MWMDirectionView * directionView;
@property (weak, nonatomic) id<MWMPlacePageViewManagerDelegate> delegate;
@property (weak, nonatomic) id<MWMPlacePageViewManagerProtocol> delegate;
@end
@implementation MWMPlacePageViewManager
- (instancetype)initWithViewController:(UIViewController *)viewController delegate:(id<MWMPlacePageViewManagerDelegate>) delegate
- (instancetype)initWithViewController:(UIViewController *)viewController delegate:(id<MWMPlacePageViewManagerProtocol>)delegate
{
self = [super init];
if (self)

View file

@ -6,7 +6,7 @@
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
@protocol MWMPlacePageViewManagerDelegate <NSObject>
@protocol MWMPlacePageViewManagerProtocol <NSObject>
- (void)dragPlacePage:(CGPoint)point;
- (void)addPlacePageViews:(NSArray *)views;

View file

@ -105,7 +105,7 @@ static CGFloat const kBottomOffset = 12.;
CGFloat const defaultWidth = 360.;
[self updatePlacePageLayout];
[self addPlacePageShadowToView:self.navigationController.view];
[self addPlacePageShadowToView:self.navigationController.view offset:CGSizeMake(0.0, -2.0)];
[self.manager addSubviews:@[self.navigationController.view] withNavigationController:self.navigationController];
self.navigationController.view.frame = CGRectMake( -defaultWidth, self.topBound + kTopOffset, defaultWidth, self.height);

View file

@ -41,7 +41,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState)
self.anchorImageView.backgroundColor = [UIColor whiteColor];
self.anchorImageView.image = nil;
[self configureContentInset];
[self addPlacePageShadowToView:self.extendedPlacePageView];
[self addPlacePageShadowToView:self.extendedPlacePageView offset:CGSizeMake(2.0, 4.0)];
[self.extendedPlacePageView addSubview:self.actionBar];
[self.manager addSubviews:@[self.extendedPlacePageView] withNavigationController:nil];
}

View file

@ -362,6 +362,7 @@
28A0AB4B0D9B1048005BE974 /* Maps_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = Maps_Prefix.pch; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
28AD73870D9D96C1002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = SOURCE_ROOT; };
29B97316FDCFA39411CA2CEA /* main.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = main.mm; sourceTree = "<group>"; };
340944A71B60EDF4008E7AF7 /* MWMSideMenuManagerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMSideMenuManagerDelegate.h; sourceTree = "<group>"; };
340F24611B14910500F874CD /* RouteState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RouteState.h; sourceTree = "<group>"; };
340F24621B14910500F874CD /* RouteState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RouteState.mm; sourceTree = "<group>"; };
340F24641B15F01D00F874CD /* MWMSideMenuDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMSideMenuDelegate.h; sourceTree = "<group>"; };
@ -1197,6 +1198,7 @@
34D56DDE1B3C310A00DFF4CC /* MWMSideMenuButtonDelegate.h */,
34BC72161B0DECAE0012A34B /* MWMSideMenuManager.h */,
34BC72171B0DECAE0012A34B /* MWMSideMenuManager.mm */,
340944A71B60EDF4008E7AF7 /* MWMSideMenuManagerDelegate.h */,
34BC72181B0DECAE0012A34B /* MWMSideMenuView.h */,
34BC72191B0DECAE0012A34B /* MWMSideMenuView.mm */,
34BC721A1B0DECAE0012A34B /* MWMSideMenuViews.xib */,