mirror of
https://github.com/zhigang1992/ECSlidingViewController.git
synced 2026-01-12 22:46:53 +08:00
API for adjusting under view widths
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
[super viewDidLoad];
|
||||
|
||||
[self.slidingViewController setAnchorRightRevealAmount:280.0f];
|
||||
self.slidingViewController.underLeftWidthLayout = ECFullWidth;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
|
||||
|
||||
@@ -10,56 +10,17 @@
|
||||
|
||||
@interface UnderRightViewController()
|
||||
@property (nonatomic, unsafe_unretained) CGFloat peekLeftAmount;
|
||||
@property (nonatomic, unsafe_unretained) BOOL isSearching;
|
||||
- (void)updateLayoutForOrientation:(UIInterfaceOrientation)orientation;
|
||||
@end
|
||||
|
||||
@implementation UnderRightViewController
|
||||
@synthesize peekLeftAmount;
|
||||
@synthesize isSearching;
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
self.peekLeftAmount = 40.0f;
|
||||
self.isSearching = NO;
|
||||
[self.slidingViewController setAnchorLeftPeekAmount:self.peekLeftAmount];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
[self updateLayoutForOrientation:self.interfaceOrientation];
|
||||
}
|
||||
|
||||
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
|
||||
{
|
||||
[self updateLayoutForOrientation:toInterfaceOrientation];
|
||||
}
|
||||
|
||||
- (void)updateLayoutForOrientation:(UIInterfaceOrientation)orientation
|
||||
{
|
||||
CGRect frame = self.view.frame;
|
||||
CGFloat newLeftEdge;
|
||||
CGFloat newWidth;
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape(orientation)) {
|
||||
newWidth = [UIScreen mainScreen].bounds.size.height;
|
||||
} else if (UIInterfaceOrientationIsPortrait(orientation)) {
|
||||
newWidth = [UIScreen mainScreen].bounds.size.width;
|
||||
}
|
||||
|
||||
if (self.isSearching) {
|
||||
newLeftEdge = 0;
|
||||
} else {
|
||||
newLeftEdge = self.peekLeftAmount;
|
||||
newWidth -= self.peekLeftAmount;
|
||||
}
|
||||
|
||||
frame.origin.x = newLeftEdge;
|
||||
frame.size.width = newWidth;
|
||||
|
||||
self.view.frame = frame;
|
||||
self.slidingViewController.underRightWidthLayout = ECVariableRevealWidth;
|
||||
}
|
||||
|
||||
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
|
||||
@@ -73,9 +34,7 @@
|
||||
frame.size.width = [UIScreen mainScreen].bounds.size.width;
|
||||
}
|
||||
self.view.frame = frame;
|
||||
} onComplete:^{
|
||||
self.isSearching = YES;
|
||||
}];
|
||||
} onComplete:nil];
|
||||
}
|
||||
|
||||
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
|
||||
@@ -89,9 +48,7 @@
|
||||
frame.size.width = [UIScreen mainScreen].bounds.size.width - self.peekLeftAmount;
|
||||
}
|
||||
self.view.frame = frame;
|
||||
} onComplete:^{
|
||||
self.isSearching = NO;
|
||||
}];
|
||||
} onComplete:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -24,6 +24,16 @@ extern NSString *const ECSlidingViewTopDidAnchorRight;
|
||||
/** Notification that gets posted when the top view is centered on the screen */
|
||||
extern NSString *const ECSlidingViewTopDidReset;
|
||||
|
||||
/** @constant ECViewWidthLayout width of under views */
|
||||
typedef enum {
|
||||
/** Under view will take up the full width of the screen */
|
||||
ECFullWidth,
|
||||
/** Under view will have a fixed width equal to anchorRightRevealAmount or anchorLeftRevealAmount. */
|
||||
ECFixedRevealWidth,
|
||||
/** Under view will have a variable width depending on rotation equal to the screen's width - anchorRightPeekAmount or anchorLeftPeekAmount. */
|
||||
ECVariableRevealWidth
|
||||
} ECViewWidthLayout;
|
||||
|
||||
/** @constant ECSide side of screen */
|
||||
typedef enum {
|
||||
/** Left side of screen */
|
||||
@@ -49,13 +59,13 @@ typedef enum {
|
||||
}
|
||||
|
||||
/** Returns the view controller that will be visible when the top view is slide to the right.
|
||||
|
||||
|
||||
This view controller is typically a menu or top-level view that switches out the top view controller.
|
||||
*/
|
||||
@property (nonatomic, strong) UIViewController *underLeftViewController;
|
||||
|
||||
/** Returns the view controller that will be visible when the top view is slide to the left.
|
||||
|
||||
|
||||
This view controller is typically a supplemental view to the top view.
|
||||
*/
|
||||
@property (nonatomic, strong) UIViewController *underRightViewController;
|
||||
@@ -104,6 +114,18 @@ typedef enum {
|
||||
*/
|
||||
@property (nonatomic, unsafe_unretained) BOOL shouldAllowUserInteractionsWhenAnchored;
|
||||
|
||||
/** Specifies the behavior for the under left width
|
||||
|
||||
By default, this is set to ECFullWidth
|
||||
*/
|
||||
@property (nonatomic, unsafe_unretained) ECViewWidthLayout underLeftWidthLayout;
|
||||
|
||||
/** Specifies the behavior for the under right width
|
||||
|
||||
By default, this is set to ECFullWidth
|
||||
*/
|
||||
@property (nonatomic, unsafe_unretained) ECViewWidthLayout underRightWidthLayout;
|
||||
|
||||
/** Returns the strategy for resetting the top view when it is anchored.
|
||||
|
||||
By default, this is set to ECPanning | ECTapping to allow both panning and tapping to reset the top view.
|
||||
|
||||
@@ -41,6 +41,8 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
- (void)underRightWillAppear;
|
||||
- (void)topDidReset;
|
||||
- (BOOL)topViewHasFocus;
|
||||
- (void)updateUnderLeftLayout;
|
||||
- (void)updateUnderRightLayout;
|
||||
|
||||
@end
|
||||
|
||||
@@ -68,6 +70,8 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
@synthesize anchorRightPeekAmount;
|
||||
@synthesize anchorLeftRevealAmount;
|
||||
@synthesize anchorRightRevealAmount;
|
||||
@synthesize underRightWidthLayout = _underRightWidthLayout;
|
||||
@synthesize underLeftWidthLayout = _underLeftWidthLayout;
|
||||
@synthesize shouldAllowUserInteractionsWhenAnchored;
|
||||
@synthesize resetStrategy;
|
||||
|
||||
@@ -106,8 +110,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
[self addChildViewController:self.underLeftViewController];
|
||||
[self.underLeftViewController didMoveToParentViewController:self];
|
||||
|
||||
[_underLeftViewController.view setAutoresizingMask:self.autoResizeToFillScreen];
|
||||
[_underLeftViewController.view setFrame:self.view.bounds];
|
||||
[self updateUnderLeftLayout];
|
||||
|
||||
[self.view insertSubview:_underLeftViewController.view atIndex:0];
|
||||
}
|
||||
@@ -124,33 +127,67 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
[self addChildViewController:self.underRightViewController];
|
||||
[self.underRightViewController didMoveToParentViewController:self];
|
||||
|
||||
[_underRightViewController.view setAutoresizingMask:self.autoResizeToFillScreen];
|
||||
[_underRightViewController.view setFrame:self.view.bounds];
|
||||
[self updateUnderRightLayout];
|
||||
|
||||
[self.view insertSubview:_underRightViewController.view atIndex:0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setUnderLeftWidthLayout:(ECViewWidthLayout)underLeftWidthLayout
|
||||
{
|
||||
if (underLeftWidthLayout == ECVariableRevealWidth && self.anchorRightPeekAmount <= 0) {
|
||||
[NSException raise:@"Invalid Width Layout" format:@"anchorRightPeekAmount must be set"];
|
||||
} else if (underLeftWidthLayout == ECFixedRevealWidth && self.anchorRightRevealAmount <= 0) {
|
||||
[NSException raise:@"Invalid Width Layout" format:@"anchorRightRevealAmount must be set"];
|
||||
}
|
||||
|
||||
_underLeftWidthLayout = underLeftWidthLayout;
|
||||
}
|
||||
|
||||
- (void)setUnderRightWidthLayout:(ECViewWidthLayout)underRightWidthLayout
|
||||
{
|
||||
if (underRightWidthLayout == ECVariableRevealWidth && self.anchorLeftPeekAmount <= 0) {
|
||||
[NSException raise:@"Invalid Width Layout" format:@"anchorLeftPeekAmount must be set"];
|
||||
} else if (underRightWidthLayout == ECFixedRevealWidth && self.anchorLeftRevealAmount <= 0) {
|
||||
[NSException raise:@"Invalid Width Layout" format:@"anchorLeftRevealAmount must be set"];
|
||||
}
|
||||
|
||||
_underRightWidthLayout = underRightWidthLayout;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
self.shouldAllowUserInteractionsWhenAnchored = NO;
|
||||
self.resetStrategy = ECTapping | ECPanning;
|
||||
self.resetTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetTopView)];
|
||||
_panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(updateTopViewHorizontalCenterWithRecognizer:)];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
[self updateUnderLeftLayout];
|
||||
[self updateUnderRightLayout];
|
||||
}
|
||||
|
||||
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
|
||||
{
|
||||
if(![self topViewHasFocus]){
|
||||
[self removeTopViewSnapshot];
|
||||
}
|
||||
|
||||
if ([self underRightShowing] && ![self topViewIsOffScreen]) {
|
||||
[self updateUnderRightLayout];
|
||||
[self updateTopViewHorizontalCenter:self.anchorLeftTopViewCenter];
|
||||
} else if ([self underRightShowing] && [self topViewIsOffScreen]) {
|
||||
[self updateUnderRightLayout];
|
||||
[self updateTopViewHorizontalCenter:-self.resettedCenter];
|
||||
} else if ([self underLeftShowing] && ![self topViewIsOffScreen]) {
|
||||
[self updateUnderLeftLayout];
|
||||
[self updateTopViewHorizontalCenter:self.anchorRightTopViewCenter];
|
||||
} else if ([self underLeftShowing] && [self topViewIsOffScreen]) {
|
||||
[self updateUnderLeftLayout];
|
||||
[self updateTopViewHorizontalCenter:self.screenWidth + self.resettedCenter];
|
||||
}
|
||||
}
|
||||
@@ -410,6 +447,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
self.underRightView.hidden = YES;
|
||||
[self.underLeftViewController viewWillAppear:NO];
|
||||
self.underLeftView.hidden = NO;
|
||||
[self updateUnderLeftLayout];
|
||||
}
|
||||
|
||||
- (void)underRightWillAppear
|
||||
@@ -420,6 +458,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
self.underLeftView.hidden = YES;
|
||||
[self.underRightViewController viewWillAppear:NO];
|
||||
self.underRightView.hidden = NO;
|
||||
[self updateUnderRightLayout];
|
||||
}
|
||||
|
||||
- (void)topDidReset
|
||||
@@ -437,4 +476,75 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset";
|
||||
return self.topView.center.x == self.resettedCenter;
|
||||
}
|
||||
|
||||
- (void)updateUnderLeftLayout
|
||||
{
|
||||
if (self.underLeftWidthLayout == ECFullWidth) {
|
||||
[self.underLeftView setAutoresizingMask:self.autoResizeToFillScreen];
|
||||
[self.underLeftView setFrame:self.view.bounds];
|
||||
} else if (self.underLeftWidthLayout == ECVariableRevealWidth && !self.topViewIsOffScreen) {
|
||||
CGRect frame = self.view.bounds;
|
||||
CGFloat newWidth;
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
|
||||
newWidth = [UIScreen mainScreen].bounds.size.height - self.anchorRightPeekAmount;
|
||||
} else {
|
||||
newWidth = [UIScreen mainScreen].bounds.size.width - self.anchorRightPeekAmount;
|
||||
}
|
||||
|
||||
frame.size.width = newWidth;
|
||||
|
||||
self.underLeftView.frame = frame;
|
||||
} else if (self.underLeftWidthLayout == ECFixedRevealWidth) {
|
||||
CGRect frame = self.view.bounds;
|
||||
|
||||
frame.size.width = self.anchorRightRevealAmount;
|
||||
self.underLeftView.frame = frame;
|
||||
} else {
|
||||
[NSException raise:@"Invalid Width Layout" format:@"underLeftWidthLayout must be a valid ECViewWidthLayout"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateUnderRightLayout
|
||||
{
|
||||
if (self.underRightWidthLayout == ECFullWidth) {
|
||||
[self.underRightViewController.view setAutoresizingMask:self.autoResizeToFillScreen];
|
||||
self.underRightView.frame = self.view.bounds;
|
||||
} else if (self.underRightWidthLayout == ECVariableRevealWidth) {
|
||||
CGRect frame = self.view.bounds;
|
||||
|
||||
CGFloat newLeftEdge;
|
||||
CGFloat newWidth;
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
|
||||
newWidth = [UIScreen mainScreen].bounds.size.height;
|
||||
} else {
|
||||
newWidth = [UIScreen mainScreen].bounds.size.width;
|
||||
}
|
||||
|
||||
if (self.topViewIsOffScreen) {
|
||||
newLeftEdge = 0;
|
||||
} else {
|
||||
newLeftEdge = self.anchorLeftPeekAmount;
|
||||
newWidth -= self.anchorLeftPeekAmount;
|
||||
}
|
||||
|
||||
frame.origin.x = newLeftEdge;
|
||||
frame.size.width = newWidth;
|
||||
|
||||
self.underRightView.frame = frame;
|
||||
} else if (self.underRightWidthLayout == ECFixedRevealWidth) {
|
||||
CGRect frame = self.view.bounds;
|
||||
|
||||
CGFloat newLeftEdge = self.screenWidth - self.anchorLeftRevealAmount;
|
||||
CGFloat newWidth = self.anchorLeftRevealAmount;
|
||||
|
||||
frame.origin.x = newLeftEdge;
|
||||
frame.size.width = newWidth;
|
||||
|
||||
self.underRightView.frame = frame;
|
||||
} else {
|
||||
[NSException raise:@"Invalid Width Layout" format:@"underRightWidthLayout must be a valid ECViewWidthLayout"];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user