Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for scroll #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 0 additions & 1 deletion REMenu/REMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#import <QuartzCore/QuartzCore.h>
#import "RECommonFunctions.h"
#import "REMenuItem.h"
#import "REMenuContainerView.h"

@class REMenu;
@class REMenuItem;
Expand Down
49 changes: 33 additions & 16 deletions REMenu/REMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ @interface REMenuItem ()

@interface REMenu ()

@property (strong, readwrite, nonatomic) UIView *menuView;
@property (strong, readwrite, nonatomic) UIScrollView *menuView;
@property (strong, readwrite, nonatomic) UIView *menuWrapperView;
@property (strong, readwrite, nonatomic) REMenuContainerView *containerView;
@property (strong, readwrite, nonatomic) UIView *containerView;
@property (strong, readwrite, nonatomic) UIButton *backgroundButton;
@property (assign, readwrite, nonatomic) BOOL isOpen;
@property (assign, readwrite, nonatomic) BOOL isAnimating;
@property (strong, readwrite, nonatomic) NSMutableArray *itemViews;
@property (weak, readwrite, nonatomic) UINavigationBar *navigationBar;
@property (weak, readwrite, nonatomic) UIView *viewToShowFrom;
@property (strong, readwrite, nonatomic) UIToolbar *toolbar;

@end
Expand Down Expand Up @@ -117,10 +118,12 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
self.isOpen = YES;
self.isAnimating = YES;

self.viewToShowFrom = view;

// Create views
//
self.containerView = ({
REMenuContainerView *view = [[REMenuContainerView alloc] init];
UIView *view = [[UIView alloc] init];
view.clipsToBounds = YES;
view.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Expand All @@ -132,7 +135,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
});

self.menuView = ({
UIView *view = [[UIView alloc] init];
UIScrollView *view = [[UIScrollView alloc] init];
if (!self.liveBlur || !REUIKitIsFlatMode()) {
view.backgroundColor = self.backgroundColor;
}
Expand Down Expand Up @@ -184,8 +187,6 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
button;
});

CGFloat navigationBarOffset = self.appearsBehindNavigationBar && self.navigationBar ? 64 : 0;

// Append new item views to REMenuView
//
for (REMenuItem *item in self.items) {
Expand All @@ -196,15 +197,15 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
itemHeight += self.cornerRadius;

UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(self.separatorOffset.width,
index * self.itemHeight + index * self.separatorHeight + 40.0 + navigationBarOffset + self.separatorOffset.height,
index * self.itemHeight + index * self.separatorHeight + self.separatorOffset.height,
rect.size.width - self.separatorOffset.width,
self.separatorHeight)];
separatorView.backgroundColor = self.separatorColor;
separatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.menuView addSubview:separatorView];

REMenuItemView *itemView = [[REMenuItemView alloc] initWithFrame:CGRectMake(0,
index * self.itemHeight + (index + 1.0) * self.separatorHeight + 40.0 + navigationBarOffset,
index * self.itemHeight + (index + 1.0) * self.separatorHeight,
rect.size.width,
itemHeight)
menu:self item:item
Expand All @@ -222,8 +223,11 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view

// Set up frames
//
self.menuWrapperView.frame = CGRectMake(0, -self.combinedHeight - navigationBarOffset, rect.size.width, self.combinedHeight + navigationBarOffset);
self.menuView.frame = self.menuWrapperView.bounds;
self.menuWrapperView.frame = CGRectMake(0, -self.combinedHeight, self.viewToShowFrom.bounds.size.width, self.combinedHeight);
CGFloat height = MIN(rect.size.height, MIN(self.viewToShowFrom.bounds.size.height - self.navigationBarOffset, self.combinedHeight));
self.menuView.frame = CGRectMake(0, 0, self.viewToShowFrom.bounds.size.width, height);
self.menuView.contentSize = CGSizeMake(self.viewToShowFrom.bounds.size.width, self.combinedHeight);

if (REUIKitIsFlatMode() && self.liveBlur) {
self.toolbar.frame = self.menuWrapperView.bounds;
}
Expand Down Expand Up @@ -257,7 +261,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
animations:^{
self.backgroundView.alpha = self.backgroundAlpha;
CGRect frame = self.menuView.frame;
frame.origin.y = -40.0 - self.separatorHeight;
frame.origin.y = self.navigationBarOffset;
self.menuWrapperView.frame = frame;
} completion:^(BOOL finished) {
self.isAnimating = NO;
Expand All @@ -272,7 +276,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
animations:^{
self.backgroundView.alpha = self.backgroundAlpha;
CGRect frame = self.menuView.frame;
frame.origin.y = -40.0 - self.separatorHeight;
frame.origin.y = self.navigationBarOffset;
self.menuWrapperView.frame = frame;
} completion:^(BOOL finished) {
self.isAnimating = NO;
Expand All @@ -289,7 +293,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
animations:^{
self.backgroundView.alpha = self.backgroundAlpha;
CGRect frame = self.menuView.frame;
frame.origin.y = -40.0 - self.separatorHeight;
frame.origin.y = self.navigationBarOffset;
self.menuWrapperView.frame = frame;
} completion:^(BOOL finished) {
self.isAnimating = NO;
Expand All @@ -298,6 +302,21 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view
}
}];
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateViewOnRotate:) name:UIDeviceOrientationDidChangeNotification object:@(rect.size.height)];
}

- (CGFloat) navigationBarOffset {
CGFloat statusBarHeight = MIN([[UIApplication sharedApplication] statusBarFrame].size.width, [[UIApplication sharedApplication] statusBarFrame].size.height);

return self.navigationBar ? self.navigationBar.frame.size.height + statusBarHeight : 0;
}

- (void) updateViewOnRotate:(NSNotification*) notification {
CGFloat height = MIN([notification.object floatValue], MIN(self.viewToShowFrom.bounds.size.height - self.navigationBarOffset, self.combinedHeight));
self.menuView.frame = CGRectMake(0, 0, self.viewToShowFrom.bounds.size.width, height);
self.menuView.contentSize = CGSizeMake(self.viewToShowFrom.bounds.size.width, self.combinedHeight);
self.menuWrapperView.frame = CGRectMake(0, self.navigationBarOffset, self.viewToShowFrom.bounds.size.width, height);
}

- (void)showInView:(UIView *)view
Expand All @@ -313,8 +332,6 @@ - (void)showFromNavigationController:(UINavigationController *)navigationControl

self.navigationBar = navigationController.navigationBar;
[self showFromRect:CGRectMake(0, 0, navigationController.navigationBar.frame.size.width, navigationController.view.frame.size.height) inView:navigationController.view];
self.containerView.appearsBehindNavigationBar = self.appearsBehindNavigationBar;
self.containerView.navigationBar = navigationController.navigationBar;
if (self.appearsBehindNavigationBar) {
[navigationController.view bringSubviewToFront:navigationController.navigationBar];
}
Expand Down Expand Up @@ -388,7 +405,7 @@ - (void)close

- (CGFloat)combinedHeight
{
return self.items.count * self.itemHeight + self.items.count * self.separatorHeight + 40.0 + self.cornerRadius;
return self.items.count * self.itemHeight + self.items.count * self.separatorHeight + self.cornerRadius;
}

- (void)setNeedsLayout
Expand Down
33 changes: 0 additions & 33 deletions REMenu/REMenuContainerView.h

This file was deleted.

51 changes: 0 additions & 51 deletions REMenu/REMenuContainerView.m

This file was deleted.

8 changes: 2 additions & 6 deletions REMenuExample/REMenuExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
30E0F7AC16D54641001949EA /* REMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 30E0F7A716D54641001949EA /* REMenu.m */; };
30E0F7AD16D54641001949EA /* REMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 30E0F7A916D54641001949EA /* REMenuItem.m */; };
30E0F7AE16D54641001949EA /* REMenuItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = 30E0F7AB16D54641001949EA /* REMenuItemView.m */; };
30E0F7B116D54CE0001949EA /* REMenuContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 30E0F7B016D54CE0001949EA /* REMenuContainerView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -59,8 +58,6 @@
30E0F7A916D54641001949EA /* REMenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = REMenuItem.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
30E0F7AA16D54641001949EA /* REMenuItemView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = REMenuItemView.h; sourceTree = "<group>"; };
30E0F7AB16D54641001949EA /* REMenuItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = REMenuItemView.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
30E0F7AF16D54CE0001949EA /* REMenuContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = REMenuContainerView.h; sourceTree = "<group>"; };
30E0F7B016D54CE0001949EA /* REMenuContainerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = REMenuContainerView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -159,8 +156,6 @@
30E0F7A916D54641001949EA /* REMenuItem.m */,
30E0F7AA16D54641001949EA /* REMenuItemView.h */,
30E0F7AB16D54641001949EA /* REMenuItemView.m */,
30E0F7AF16D54CE0001949EA /* REMenuContainerView.h */,
30E0F7B016D54CE0001949EA /* REMenuContainerView.m */,
);
name = REMenu;
path = ../REMenu;
Expand Down Expand Up @@ -235,7 +230,6 @@
30E0F7AC16D54641001949EA /* REMenu.m in Sources */,
30E0F7AD16D54641001949EA /* REMenuItem.m in Sources */,
30E0F7AE16D54641001949EA /* REMenuItemView.m in Sources */,
30E0F7B116D54CE0001949EA /* REMenuContainerView.m in Sources */,
30B00DDB17CCFD280010D439 /* ActivityViewController.m in Sources */,
30B00DDC17CCFD280010D439 /* ExploreViewController.m in Sources */,
30B00DDD17CCFD280010D439 /* HomeViewController.m in Sources */,
Expand Down Expand Up @@ -320,6 +314,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
ENABLE_BITCODE = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "REMenuExample/REMenuExample-Prefix.pch";
INFOPLIST_FILE = "REMenuExample/REMenuExample-Info.plist";
Expand All @@ -336,6 +331,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
ENABLE_BITCODE = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "REMenuExample/REMenuExample-Prefix.pch";
INFOPLIST_FILE = "REMenuExample/REMenuExample-Info.plist";
Expand Down