From f4cc747a10c1790d1091e9b58c769cdc7bfed6ce Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sun, 16 Jun 2013 23:21:10 -0500 Subject: [PATCH 1/6] Added a newline at the end of the file to silence the compiler warning --- MFSlidingView/MFSlidingView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MFSlidingView/MFSlidingView.h b/MFSlidingView/MFSlidingView.h index 48dd306..df0d6b9 100644 --- a/MFSlidingView/MFSlidingView.h +++ b/MFSlidingView/MFSlidingView.h @@ -53,4 +53,4 @@ typedef enum { + (void) slideOut; -@end \ No newline at end of file +@end From a44206859fd3af7c3fbe41b48b0ef6f2ec3b4132 Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sun, 16 Jun 2013 23:21:32 -0500 Subject: [PATCH 2/6] Properly update the positioning if the device orientation changes --- MFSlidingView/MFSlidingView.m | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/MFSlidingView/MFSlidingView.m b/MFSlidingView/MFSlidingView.m index c64e1aa..357374f 100644 --- a/MFSlidingView/MFSlidingView.m +++ b/MFSlidingView/MFSlidingView.m @@ -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]; @@ -452,4 +458,21 @@ -(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 beginAnimations:@"slideIn" context:nil]; + [UIView setAnimationDelegate:self]; + + frame = self.bodyFrame; + frame.origin = [self onScreenCoordinates]; + bodyView.frame = frame; + + [UIView commitAnimations]; +} + @end From 1866c8273ca1421640338d0813d5e7bc9c9046eb Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sat, 17 Oct 2020 14:01:30 -0400 Subject: [PATCH 3/6] Warning fix --- MFSlidingView/MFSlidingView.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MFSlidingView/MFSlidingView.h b/MFSlidingView/MFSlidingView.h index df0d6b9..b330292 100644 --- a/MFSlidingView/MFSlidingView.h +++ b/MFSlidingView/MFSlidingView.h @@ -48,8 +48,8 @@ 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; From 9d5dc4fbf293d33dc87ccb7d64b1f5a25a34f136 Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Mon, 1 Mar 2021 01:00:44 -0500 Subject: [PATCH 4/6] warning fixes --- MFSlidingView/MFSlidingView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MFSlidingView/MFSlidingView.m b/MFSlidingView/MFSlidingView.m index 357374f..de2cbbb 100644 --- a/MFSlidingView/MFSlidingView.m +++ b/MFSlidingView/MFSlidingView.m @@ -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; From 3a6c2923a2e3d8f8c8a7ec9e452d8f549d05bc9b Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Sun, 9 Oct 2022 13:30:06 -0400 Subject: [PATCH 5/6] Update to block-based animations --- MFSlidingView/MFSlidingView.m | 108 ++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/MFSlidingView/MFSlidingView.m b/MFSlidingView/MFSlidingView.m index de2cbbb..b440bd9 100644 --- a/MFSlidingView/MFSlidingView.m +++ b/MFSlidingView/MFSlidingView.m @@ -323,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; } @@ -339,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 { @@ -392,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]; @@ -421,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 { @@ -438,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 @@ -465,14 +470,15 @@ - (void)orientationDidChange:(NSNotification *)notification { frame.origin = CGPointMake(0, 0); self.frame = frame; - [UIView beginAnimations:@"slideIn" context:nil]; - [UIView setAnimationDelegate:self]; - - frame = self.bodyFrame; - frame.origin = [self onScreenCoordinates]; - bodyView.frame = frame; - - [UIView commitAnimations]; + [UIView animateWithDuration:0.25 animations:^{ + CGRect newFrame = self.bodyFrame; + newFrame.origin = [self onScreenCoordinates]; + self->bodyView.frame = newFrame; + + + } completion:^(BOOL finished) { + + }]; } @end From c47b6c3698b3d52f6b07c7325cf1b3c9f115fdc8 Mon Sep 17 00:00:00 2001 From: "Evan D. Schoenberg, M.D" Date: Tue, 1 Nov 2022 16:43:28 -0400 Subject: [PATCH 6/6] Respect safeAreaInsets --- MFSlidingView/MFSlidingView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MFSlidingView/MFSlidingView.m b/MFSlidingView/MFSlidingView.m index b440bd9..2570b5e 100644 --- a/MFSlidingView/MFSlidingView.m +++ b/MFSlidingView/MFSlidingView.m @@ -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; }