Permalink
Browse files

refactoring to work correctly with 4-inch display

  • Loading branch information...
1 parent fd8df1b commit 4f6a78036cee58c4fb0e0c899fab5e123216809e @reednj committed Oct 17, 2012
Showing with 26 additions and 47 deletions.
  1. +26 −47 Source/UIViewController+TDSemiModalExtension.m
View
73 Source/UIViewController+TDSemiModalExtension.m
@@ -12,78 +12,42 @@ @implementation UIViewController (TDSemiModalExtension)
// Use this to show the modal view (pops-up from the bottom)
- (void) presentSemiModalViewController:(TDSemiModalViewController*)vc {
-#define DEGREES_TO_RADIANS(x) (M_PI * (x)/180.0)
-
UIView* modalView = vc.view;
UIView* coverView = vc.coverView;
- //UIWindow* mainWindow = [(id)[[UIApplication sharedApplication] delegate] window];
-
- CGPoint middleCenter = self.view.center;
- CGSize offSize = [UIScreen mainScreen].bounds.size;
-
- UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
-
- CGPoint offScreenCenter = CGPointZero;
-
- if(orientation == UIInterfaceOrientationLandscapeLeft ||
- orientation == UIInterfaceOrientationLandscapeRight) {
-
- offScreenCenter = CGPointMake(offSize.height / 2.0, offSize.width * 1.2);
- middleCenter = CGPointMake(middleCenter.y, middleCenter.x);
- [modalView setBounds:CGRectMake(0, 0, 480, 300)];
- [coverView setFrame:CGRectMake(0, 0, 480, 300)];
- }
- else {
- offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.2);
- [modalView setBounds:CGRectMake(0, 0, 320, 460)];
- [coverView setFrame:CGRectMake(0, 0, 320, 460)];
- }
-
- // we start off-screen
- modalView.center = offScreenCenter;
-
- coverView.alpha = 0.0f;
+ coverView.frame = self.view.bounds;
+ coverView.alpha = 0.0f;
+
+ modalView.frame = self.view.bounds;
+ modalView.center = self.offscreenCenter;
[self.view addSubview:coverView];
[self.view addSubview:modalView];
- // Show it with a transition effect
- [UIView beginAnimations:nil context:nil];
+ [UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
- modalView.center = middleCenter;
+ modalView.frame = CGRectMake(0, 0, modalView.frame.size.width, modalView.frame.size.height);
coverView.alpha = 0.5;
[UIView commitAnimations];
}
-// Use this to slide the semi-modal view back down.
-(void) dismissSemiModalViewController:(TDSemiModalViewController*)vc {
double animationDelay = 0.7;
UIView* modalView = vc.view;
UIView* coverView = vc.coverView;
-
- CGSize offSize = [UIScreen mainScreen].bounds.size;
-
- CGPoint offScreenCenter = CGPointZero;
-
- UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
- if(orientation == UIInterfaceOrientationLandscapeLeft ||
- orientation == UIInterfaceOrientationLandscapeRight) {
- offScreenCenter = CGPointMake(offSize.height / 2.0, offSize.width * 1.5);
- }
- else {
- offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
- }
+
[UIView beginAnimations:nil context:(__bridge void *)(modalView)];
[UIView setAnimationDuration:animationDelay];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(dismissSemiModalViewControllerEnded:finished:context:)];
- modalView.center = offScreenCenter;
+
+ modalView.center = self.offscreenCenter;
coverView.alpha = 0.0f;
+
[UIView commitAnimations];
[coverView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:animationDelay];
@@ -96,4 +60,19 @@ - (void) dismissSemiModalViewControllerEnded:(NSString *)animationID finished:(N
}
+-(CGPoint) offscreenCenter {
+ CGPoint offScreenCenter = CGPointZero;
+
+ UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
+ CGSize offSize = UIScreen.mainScreen.bounds.size;
+
+ if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
+ offScreenCenter = CGPointMake(offSize.height / 2.0, offSize.width * 1.5);
+ } else {
+ offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
+ }
+
+ return offScreenCenter;
+}
+
@end

0 comments on commit 4f6a780

Please sign in to comment.