Skip to content

Instantly share code, notes, and snippets.

@iolate
Last active December 16, 2015 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iolate/5479906 to your computer and use it in GitHub Desktop.
Save iolate/5479906 to your computer and use it in GitHub Desktop.
[THEOS] Additional UIWindows - Rotating UIWindow when orientation was changed.
#define UPDATE_ORIENTATION_NOTI CFSTR("iolate/UpdateOrientation")
static UIWindow* additionalWindow = nil;
static UIView* mainViewInWindow = nil;
static void updateOrientation(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
int orientation_ = 0;
switch (orientation) {
case UIInterfaceOrientationPortraitUpsideDown:
orientation_ = 180;
break;
case UIInterfaceOrientationLandscapeLeft:
orientation_ = -90;
break;
case UIInterfaceOrientationLandscapeRight:
orientation_ = 90;
break;
case UIInterfaceOrientationPortrait:
default:
orientation_ = 0;
}
[UIView animateWithDuration:0.3f animations:^{
additionalWindow.transform = CGAffineTransformMakeRotation(orientation_ * M_PI / 180.0f);
[additionalWindow setFrame:[[UIScreen mainScreen] bounds]];
[mainViewInWindow setFrame:[beeWindow bounds]];
} completion:nil];
}
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateOrientation, UPDATE_ORIENTATION_NOTI, NULL, CFNotificationSuspensionBehaviorCoalesce);
additionalWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
mainViewInWindow = [[UIView alloc] initWithFrame:[beeWindow bounds]];
[mainViewInWindow setAutoresizesSubviews:YES];
[additionalWindow addSubview:mainViewInWindow];
}
#define UPDATE_ORIENTATION_NOTI CFSTR("iolate/UpdateOrientation")
%hook SpringBoard
-(void)frontDisplayDidChange {
//iOS3.2-5
%orig;
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), UPDATE_ORIENTATION_NOTI, NULL, NULL, true);
}
- (void)noteInterfaceOrientationChanged:(int)orientation {
//iOS3.2-5
%orig;
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), UPDATE_ORIENTATION_NOTI, NULL, NULL, true);
}
-(void)noteInterfaceOrientationChanged:(int)orientation duration:(double)duration {
//iOS6
%orig;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 5);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), UPDATE_ORIENTATION_NOTI, NULL, NULL, true);
});
}
%end
@nevyn
Copy link

nevyn commented Aug 12, 2014

You shouldn't be setting the frame of a UIView when the transform is not identity; the result is undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment