Skip to content

Loading…

Added the ability to move the modal view up #41

Open
wants to merge 1 commit into from

2 participants

@tranqy

In our implementation it felt better to move the view then resize when the keyboard was displayed. We added this method to move instead of resize and wanted to share.

Great lib, thank you!

@kentnguyen
Owner

Good suggestion. However, this is not exactly easy to use on iPad, so I will keep it as open Pull Request for other users to decide if they want to use it in their code. I'd prefer to keep the library as "modal" instead of being pushed out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
Showing with 21 additions and 0 deletions.
  1. +3 −0 Source/UIViewController+KNSemiModal.h
  2. +18 −0 Source/UIViewController+KNSemiModal.m
View
3 Source/UIViewController+KNSemiModal.h
@@ -32,6 +32,8 @@
#define kSemiModalDidShowNotification @"kSemiModalDidShowNotification"
#define kSemiModalDidHideNotification @"kSemiModalDidHideNotification"
#define kSemiModalWasResizedNotification @"kSemiModalWasResizedNotification"
+#define kSemiModalWasMovedNotification @"kSemiModalWasMovedNotification"
+
extern const struct KNSemiModalOptionKeys {
__unsafe_unretained NSString *traverseParentHierarchy; // boxed BOOL. default is YES.
@@ -78,6 +80,7 @@ typedef void (^KNTransitionCompletionBlock)(void);
// Dismiss & resize
-(void)resizeSemiView:(CGSize)newSize;
+-(void)moveSemiViewToTopWithMargin:(CGFloat)topMargin;
-(void)dismissSemiModalView;
-(void)dismissSemiModalViewWithCompletion:(KNTransitionCompletionBlock)completion;
View
18 Source/UIViewController+KNSemiModal.m
@@ -363,6 +363,24 @@ - (void)resizeSemiView:(CGSize)newSize {
}];
}
+-(void)moveSemiViewToTopWithMargin:(CGFloat)topMargin {
+ UIView * target = [self parentTarget];
+ UIView * modal = [target.subviews objectAtIndex:target.subviews.count-1];
+ CGRect newFrame = modal.frame;
+ newFrame.origin.y = topMargin;
+ NSTimeInterval duration = [[self ym_optionOrDefaultForKey:KNSemiModalOptionKeys.animationDuration] doubleValue];
+ [UIView animateWithDuration:duration animations:^{
+ modal.frame = newFrame;
+ } completion:^(BOOL finished) {
+ if(finished){
+ [[NSNotificationCenter defaultCenter] postNotificationName:kSemiModalWasMovedNotification
+ object:self];
+ }
+ }];
+
+}
+
+
@end
Something went wrong with that request. Please try again.