Created
September 11, 2010 07:52
-
-
Save joshaber/574966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)floatIntoWindow { | |
if(self.superview == self.window) return; | |
CGRect newFrame = [self.superview convertRect:self.frame toView:nil]; | |
[self.window addSubview:self]; | |
self.transform = [self transformForCurrentInterfaceOrientation]; | |
self.frame = newFrame; | |
} | |
- (void)unfloatIntoView:(UIView *)newSuperview { | |
if(self.superview == newSuperview) return; | |
CGRect newFrame = [newSuperview convertRect:self.frame fromView:nil]; | |
[newSuperview addSubview:self]; | |
self.transform = newSuperview.transform; | |
self.frame = newFrame; | |
} | |
- (CGAffineTransform)transformForInterfaceOrientation:(UIInterfaceOrientation)orientation { | |
if(orientation == UIInterfaceOrientationPortrait) { | |
return CGAffineTransformIdentity; | |
} else if(orientation == UIInterfaceOrientationLandscapeLeft) { | |
return CGAffineTransformMakeRotation(270.0f * (CGFloat) M_PI / 180.0f); | |
} else if(orientation == UIInterfaceOrientationLandscapeRight) { | |
return CGAffineTransformMakeRotation(90.0f * (CGFloat) M_PI / 180.0f); | |
} else if(orientation == UIInterfaceOrientationPortraitUpsideDown) { | |
return CGAffineTransformMakeRotation(180.0f * (CGFloat) M_PI / 180.0f); | |
} | |
return CGAffineTransformIdentity; | |
} | |
- (CGAffineTransform)transformForCurrentInterfaceOrientation { | |
return [self transformForInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment