Skip to content
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
6 changes: 3 additions & 3 deletions MFSlidingView/MFSlidingView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ typedef enum {
offScreenPosition:(SlidingViewOffScreenPosition)offScreenPosition
title:(NSString *)title
options:(SlidingViewOptions)options
doneBlock:(void (^)())doneBlock
cancelBlock:(void (^)())cancelBlock;
doneBlock:(void (^)(void))doneBlock
cancelBlock:(void (^)(void))cancelBlock;

+ (void) slideOut;

@end
@end
123 changes: 76 additions & 47 deletions MFSlidingView/MFSlidingView.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ + (MFSlidingView *) slideView:(UIView *)view
offScreenPosition:(SlidingViewOffScreenPosition)offScreenPosition
title:(NSString *)title
options:(SlidingViewOptions)options
doneBlock:(void (^)())doneBlock
cancelBlock:(void (^)())cancelBlock {
doneBlock:(void (^)(void))doneBlock
cancelBlock:(void (^)(void))cancelBlock {

MFSlidingView *slidingView = [[MFSlidingView alloc] initWithContentView:view];
slidingView.doneBlock = doneBlock;
Expand Down Expand Up @@ -251,13 +251,13 @@ - (CGPoint) onScreenCoordinates {

switch (self.finalPosition) {
case TopOfScreen:
finalCoordinates.y = 0.0;
finalCoordinates.y = self.containerView.safeAreaInsets.top;
break;
case MiddleOfScreen:
finalCoordinates.y = (self.containerView.bounds.size.height - frame.size.height)/2;
break;
case BottomOfScreen:
finalCoordinates.y = self.containerView.bounds.size.height - frame.size.height;
finalCoordinates.y = self.containerView.bounds.size.height - frame.size.height - self.containerView.safeAreaInsets.bottom;
break;
}

Expand Down Expand Up @@ -292,6 +292,12 @@ - (void) slideIntoView:(UIView *)wrapper
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
}

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];



if(self.contentView.frame.size.width < self.containerView.frame.size.width) {
bodyView.backgroundColor = [UIColor blackColor];
Expand All @@ -317,14 +323,15 @@ - (void) slideIntoView:(UIView *)wrapper
[bodyView addSubview:self.contentView];

// slide in animation
[UIView beginAnimations:@"slideIn" context:nil];
[UIView setAnimationDelegate:self];

frame.origin = [self onScreenCoordinates];
bodyView.frame = frame;
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.55];

[UIView commitAnimations];
[UIView animateWithDuration:0.25 animations:^{
CGRect newFrame = frame;
newFrame.origin = [self onScreenCoordinates];
self->bodyView.frame = newFrame;
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.55];

} completion:^(BOOL finished) {

}];

framePriorToKeyboardMovement = bodyView.frame;
}
Expand All @@ -333,25 +340,15 @@ - (void) slideOut
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[UIView beginAnimations:@"slideOut" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

CGRect frame = bodyView.frame;
frame.origin = [self offScreenCoordinates];
bodyView.frame = frame;
self.backgroundColor = [UIColor clearColor];

[UIView commitAnimations];
}
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = self->bodyView.frame;
frame.origin = [self offScreenCoordinates];
self->bodyView.frame = frame;
self.backgroundColor = [UIColor clearColor];

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"slideOut"]) {
} completion:^(BOOL finished) {
if(self.superview) [self removeFromSuperview];
} else if ([animationID isEqualToString:@"slideIn"]) {

}
}];
}

- (void) cancelPressed:(id)sender {
Expand Down Expand Up @@ -386,12 +383,29 @@ - (BOOL) adjustToFirstResponder {
frame.origin.y = idealPosition - firstResponderBounds.origin.y;

// Shrink view's height by the keyboard's height, and scroll to show the text field/view being edited
[UIView beginAnimations:nil context:NULL];
bodyView.frame = frame;
[UIView commitAnimations];

[UIView animateWithDuration:0.25 animations:^{
self->bodyView.frame = frame;

} completion:^(BOOL finished) {
}];

return YES;
}

static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCurve curve)
{
switch (curve) {
case UIViewAnimationCurveEaseInOut:
return UIViewAnimationOptionCurveEaseInOut;
case UIViewAnimationCurveEaseIn:
return UIViewAnimationOptionCurveEaseIn;
case UIViewAnimationCurveEaseOut:
return UIViewAnimationOptionCurveEaseOut;
case UIViewAnimationCurveLinear:
return UIViewAnimationOptionCurveLinear;
}
}

- (void)keyboardWillShow:(NSNotification*)notification {
UIView *firstResponder = [self findFirstResponderBeneathView:self];
Expand All @@ -415,14 +429,12 @@ - (void)keyboardWillShow:(NSNotification*)notification {
NSInteger animationCurve = [[[notification userInfo]
objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];

// Shrink view's height by the keyboard's height, and scroll to show the text field/view being edited
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];

bodyView.frame = frame;

[UIView commitAnimations];
[UIView animateWithDuration:animationDuration delay:0 options:animationOptionsWithCurve(animationCurve) animations:^{
self->bodyView.frame = frame;

} completion:^(BOOL finished) {

}];
}

- (void)keyboardWillHide:(NSNotification*)notification {
Expand All @@ -432,13 +444,12 @@ - (void)keyboardWillHide:(NSNotification*)notification {
objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];

// Restore dimensions to prior size
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];

bodyView.frame = framePriorToKeyboardMovement;

[UIView commitAnimations];
[UIView animateWithDuration:animationDuration delay:0 options:animationCurve animations:^{
self->bodyView.frame = self->framePriorToKeyboardMovement;

} completion:^(BOOL finished) {

}];
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Expand All @@ -452,4 +463,22 @@ -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
}
}

- (void)orientationDidChange:(NSNotification *)notification {
CGRect frame;

frame.size = self.containerView.frame.size;
frame.origin = CGPointMake(0, 0);
self.frame = frame;

[UIView animateWithDuration:0.25 animations:^{
CGRect newFrame = self.bodyFrame;
newFrame.origin = [self onScreenCoordinates];
self->bodyView.frame = newFrame;


} completion:^(BOOL finished) {

}];
}

@end