Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 87 additions & 46 deletions Example/JVFloatingDrawer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "JVFloatingDrawerSpringAnimator.h"
#import "AppDelegate.h"

@interface JVDrawerSettingsTableViewController ()
@interface JVDrawerSettingsTableViewController () <JVFloatingDrawerPanGestureDelegate>

@property (nonatomic, strong, readonly) JVFloatingDrawerSpringAnimator *drawerAnimator;

Expand Down Expand Up @@ -95,4 +95,10 @@ - (void)didReceiveMemoryWarning {
// Dispose of any resources that can be recreated.
}

#pragma mark - JVFloatingDrawerPanGestureDelegate

- (BOOL)shouldOpenDrawerWithSide:(JVFloatingDrawerSide)drawerSide {
return YES;
}

@end
10 changes: 9 additions & 1 deletion Example/JVFloatingDrawer/JVGitHubViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#import "JVGitHubViewController.h"
#import "AppDelegate.h"
#import "JVFloatingDrawerViewController.h"


static NSString * const kJVGithubProjectPage = @"http://github.com/JVillella/JVFloatingDrawer";

@interface JVGitHubViewController ()
@interface JVGitHubViewController () <JVFloatingDrawerPanGestureDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webview;

Expand Down Expand Up @@ -40,4 +42,10 @@ - (IBAction)actionToggleRightDrawer:(id)sender {
[[AppDelegate globalDelegate] toggleRightDrawer:self animated:YES];
}

#pragma mark - JVFloatingDrawerPanGestureDelegate

- (BOOL)shouldOpenDrawerWithSide:(JVFloatingDrawerSide)drawerSide {
return YES;
}

@end
1 change: 1 addition & 0 deletions Example/JVFloatingDrawer/JVLeftDrawerTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @interface JVLeftDrawerTableViewCell ()
@implementation JVLeftDrawerTableViewCell

- (void)awakeFromNib {
[super awakeFromNib];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
source 'https://github.com/CocoaPods/Specs.git'

target 'JVFloatingDrawer', :exclusive => true do
target 'JVFloatingDrawer' do
pod "JVFloatingDrawer", :path => "../"
end

target 'JVFloatingDrawerTests', :exclusive => true do
target 'JVFloatingDrawerTests' do
pod "JVFloatingDrawer", :path => "../"
end

6 changes: 4 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ DEPENDENCIES:

EXTERNAL SOURCES:
JVFloatingDrawer:
:path: "../"
:path: ../

SPEC CHECKSUMS:
JVFloatingDrawer: 4782b1df21411aef2c1818f3b346cace02cc2e24

COCOAPODS: 0.37.2
PODFILE CHECKSUM: f05e356e11bb0527b08f50ec30940e20a7f1673c

COCOAPODS: 1.3.1
17 changes: 17 additions & 0 deletions Pod/Classes/JVFloatingDrawerAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@
*/
- (void)didRotateOpenDrawerWithOpenSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)sideView centerView:(UIView *)centerView;

/**
* Implementations should move the side view and the center view.
*
* @param trans The point that your finger points to
* @param sideView The view of the side of the drawer to be presented
* @param centerView The center view
*/
@optional
- (void)moveWithTranslation:(CGPoint)trans
sideView:(UIView *)sideView
centerView:(UIView *)centerView;

@optional
- (void)moveBackWithTranslation:(CGPoint)trans
sideView:(UIView *)sideView
centerView:(UIView *)centerView;

@end


72 changes: 61 additions & 11 deletions Pod/Classes/JVFloatingDrawerSpringAnimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (void)setup {
#pragma mark Presentation/Dismissal

- (void)presentationWithSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)sideView centerView:(UIView *)centerView animated:(BOOL)animated completion:(void (^)(BOOL))completion {
void (^springAnimation)() = ^{
void (^springAnimation)(void) = ^{
[self applyTransformsWithSide:drawerSide sideView:sideView centerView:centerView];
};

Expand All @@ -53,7 +53,7 @@ - (void)presentationWithSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *
}

- (void)dismissWithSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)sideView centerView:(UIView *)centerView animated:(BOOL)animated completion:(void (^)(BOOL))completion {
void (^springAnimation)() = ^{
void (^springAnimation)(void) = ^{
[self removeTransformsWithSide:drawerSide sideView:sideView centerView:centerView];
};

Expand All @@ -74,7 +74,7 @@ - (void)dismissWithSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)side
- (void)willRotateOpenDrawerWithOpenSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)sideView centerView:(UIView *)centerView {}

- (void)didRotateOpenDrawerWithOpenSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)sideView centerView:(UIView *)centerView {
void (^springAnimation)() = ^{
void (^springAnimation)(void) = ^{
[self applyTransformsWithSide:drawerSide sideView:sideView centerView:centerView];
};

Expand Down Expand Up @@ -121,18 +121,19 @@ - (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view {
#pragma mark Transforms

- (void)applyTransformsWithSide:(JVFloatingDrawerSide)drawerSide sideView:(UIView *)sideView centerView:(UIView *)centerView {
CGFloat direction = drawerSide == JVFloatingDrawerSideLeft ? 1.0 : -1.0;
CGFloat sideWidth = sideView.bounds.size.width;
CGFloat centerWidth = centerView.bounds.size.width;
CGFloat centerViewHorizontalOffset = direction * sideWidth;
CGFloat scaledCenterViewHorizontalOffset = direction * (sideWidth - (centerWidth - kJVCenterViewDestinationScale * centerWidth) / 2.0);
CGFloat sideWidth = sideView.bounds.size.width;
CGFloat direction = (drawerSide == JVFloatingDrawerSideLeft) ? 1.0 : -1.0;

CGAffineTransform sideTranslate = CGAffineTransformMakeTranslation(centerViewHorizontalOffset, 0.0);
sideView.transform = sideTranslate;
CGFloat sideViewHorizontalOffset = direction * sideWidth;
CGFloat centerScaleValue = kJVCenterViewDestinationScale;

CGFloat scaledCenterViewHorizontalOffset = sideViewHorizontalOffset - direction * (sideWidth * (1 - centerScaleValue));

CGAffineTransform sideTranslate = CGAffineTransformMakeTranslation(sideViewHorizontalOffset, 0.0);
sideView.transform = sideTranslate;

CGAffineTransform centerScale = CGAffineTransformMakeScale(centerScaleValue, centerScaleValue);
CGAffineTransform centerTranslate = CGAffineTransformMakeTranslation(scaledCenterViewHorizontalOffset, 0.0);
CGAffineTransform centerScale = CGAffineTransformMakeScale(kJVCenterViewDestinationScale, kJVCenterViewDestinationScale);
centerView.transform = CGAffineTransformConcat(centerScale, centerTranslate);
}

Expand All @@ -141,4 +142,53 @@ - (void)removeTransformsWithSide:(JVFloatingDrawerSide)drawerSide sideView:(UIVi
centerView.transform = CGAffineTransformIdentity;
}

- (void)moveBackWithTranslation:(CGPoint)trans sideView:(UIView *)sideView centerView:(UIView *)centerView {
CGFloat transX = trans.x;
CGFloat transWidth = fabs(transX);
BOOL toLeft = (transX >= 0.0);

CGFloat sideWidth = sideView.bounds.size.width;

CGFloat direction = toLeft ? 1.0 : -1.0;
CGFloat ratio = (transWidth / sideWidth);

if (ratio > 1.0) return;

CGFloat sideViewHorizontalOffset = direction * (transWidth - sideWidth);
CGFloat centerScaleValue = kJVCenterViewDestinationScale + (1.0 - kJVCenterViewDestinationScale) * ratio;

CGFloat scaledCenterViewHorizontalOffset = sideViewHorizontalOffset * centerScaleValue;

CGAffineTransform sideTranslate = CGAffineTransformMakeTranslation(sideViewHorizontalOffset, 0.0);
sideView.transform = sideTranslate;

CGAffineTransform centerScale = CGAffineTransformMakeScale(centerScaleValue, centerScaleValue);
CGAffineTransform centerTranslate = CGAffineTransformMakeTranslation(scaledCenterViewHorizontalOffset, 0.0);
centerView.transform = CGAffineTransformConcat(centerScale, centerTranslate);
}

- (void)moveWithTranslation:(CGPoint)trans sideView:(UIView *)sideView centerView:(UIView *)centerView {
CGFloat transX = trans.x;
CGFloat transWidth = fabs(transX);
BOOL toLeft = (transX >= 0.0);

CGFloat sideWidth = sideView.bounds.size.width;
CGFloat direction = toLeft ? 1.0 : -1.0;
CGFloat ratio = (transWidth / sideWidth);

if (ratio > 1.0) return;

CGFloat sideViewHorizontalOffset = direction * transWidth;
CGFloat centerScaleValue = 1.0 - (1.0 - kJVCenterViewDestinationScale) * ratio;

CGFloat scaledCenterViewHorizontalOffset = sideViewHorizontalOffset - direction * (transWidth * (1 - centerScaleValue));

CGAffineTransform sideTranslate = CGAffineTransformMakeTranslation(sideViewHorizontalOffset, 0.0);
sideView.transform = sideTranslate;

CGAffineTransform centerScale = CGAffineTransformMakeScale(centerScaleValue, centerScaleValue);
CGAffineTransform centerTranslate = CGAffineTransformMakeTranslation(scaledCenterViewHorizontalOffset, 0.0);
centerView.transform = CGAffineTransformConcat(centerScale, centerTranslate);
}

@end
2 changes: 1 addition & 1 deletion Pod/Classes/JVFloatingDrawerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "JVFloatingDrawerView.h"

static const CGFloat kJVCenterViewContainerCornerRadius = 5.0;
static const CGFloat kJVCenterViewContainerCornerRadius = 6.0;
static const CGFloat kJVDefaultViewContainerWidth = 280.0;

@interface JVFloatingDrawerView ()
Expand Down
11 changes: 11 additions & 0 deletions Pod/Classes/JVFloatingDrawerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ typedef NS_ENUM(NSInteger, JVFloatingDrawerSide) {
JVFloatingDrawerSideRight
};

@protocol JVFloatingDrawerPanGestureDelegate <NSObject>
@optional
- (BOOL)shouldOpenDrawerWithSide:(JVFloatingDrawerSide)drawerSide;

@end

@interface JVFloatingDrawerViewController : UIViewController

#pragma mark - Managed View Controllers
Expand Down Expand Up @@ -50,4 +56,9 @@ typedef NS_ENUM(NSInteger, JVFloatingDrawerSide) {

@property (nonatomic, strong) UIImage *backgroundImage;

#pragma mark - Pan Gesture

@property (nonatomic, assign) CGFloat minimumDragDistance;
@property (nonatomic, assign) CGFloat dragRespondingWidth;

@end
Loading