Permalink
Browse files

Autorotate datePicker correctly with resizing etc

  • Loading branch information...
reednj committed Nov 25, 2010
1 parent bd9e080 commit e4ef9410993b2037dfb8cdfd171afd5482853494
@@ -168,6 +168,7 @@
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "TDSemiModal" */;
compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
@@ -254,7 +255,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
PREBINDING = NO;
- SDKROOT = iphoneos4.0;
+ SDKROOT = iphoneos4.1;
};
name = Debug;
};
@@ -13,9 +13,7 @@ @implementation TDSemiModalViewController
-(void)viewDidLoad {
[super viewDidLoad];
-
- //self.coverView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
- self.coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
+
self.coverView.backgroundColor = UIColor.blackColor;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -26,36 +26,33 @@ - (void) presentSemiModalViewController:(TDSemiModalViewController*)vc {
CGPoint offScreenCenter = CGPointZero;
- if(orientation == UIInterfaceOrientationPortraitUpsideDown) {
- offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.2);
- [modalView setBounds:CGRectMake(0, 0, 320, 460)];
- }
- else if(orientation == UIInterfaceOrientationLandscapeLeft) {
- offScreenCenter = CGPointMake(offSize.height / 2.0, offSize.width * 2.0);
- [modalView setBounds:CGRectMake(0, 0, 480, 320)];
+ 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)];
}
- else if(orientation == UIInterfaceOrientationLandscapeRight) {
- offScreenCenter = CGPointMake(offSize.height / 2.0, offSize.width * 2.0);
- [modalView setBounds:CGRectMake(0, 0, 480, 320)];
- } else {
+ 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)];
}
-
-
- modalView.center = offScreenCenter;
- coverView.alpha = 0.5;
+
// we start off-screen
-
+ modalView.center = offScreenCenter;
+
+ coverView.alpha = 0.0f;
+
[self.view addSubview:coverView];
[self.view addSubview:modalView];
-
+
// Show it with a transition effect
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
-
+
modalView.center = middleCenter;
- //coverView.alpha = 0.5;
+ coverView.alpha = 0.5;
[UIView commitAnimations];
@@ -69,18 +66,23 @@ -(void) dismissSemiModalViewController:(TDSemiModalViewController*)vc {
CGSize offSize = [UIScreen mainScreen].bounds.size;
-
-
CGPoint offScreenCenter = CGPointZero;
- offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
-
-
+
+ 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:modalView];
[UIView setAnimationDuration:animationDelay];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(dismissSemiModalViewControllerEnded:finished:context:)];
modalView.center = offScreenCenter;
+ coverView.alpha = 0.0f;
[UIView commitAnimations];
[coverView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:animationDelay];

0 comments on commit e4ef941

Please sign in to comment.