私はこれを試していませんUIWindow
が、プロパティがありますrootViewController
ウィンドウのルートビューコントローラ。
@property(nonatomic, retain) UIViewController *rootViewController
説明
ルートビューコントローラは、ウィンドウのコンテンツビューを提供します。View Controllerをこのプロパティに(プログラムでまたはInterface Builderを使用して)割り当てると、ViewControllerのビューがウィンドウのコンテンツビューとしてインストールされます。ウィンドウに既存のビュー階層がある場合、新しいビューがインストールされる前に古いビューが削除されます。
このプロパティのデフォルト値はnilです。
可用性
iOS4.0以降で利用できます。
UIWindow.hで宣言
このルートビューコントローラーを提供する必要があるため、rootViewContollerのビューに追加して、外側の回転を正しく処理できるはずです。
別の解決策は、別のビューコントローラを使用して、ビューを表示しながらウィンドウをカスタムのものと交換することです。このトリックの動作は、TSAlertViewの実装で確認できます。
- (void) show
{
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:[NSDate date]];
TSAlertViewController* avc = [[[TSAlertViewController alloc] init] autorelease];
avc.view.backgroundColor = [UIColor clearColor];
// $important - the window is released only when the user clicks an alert view button
TSAlertOverlayWindow* ow = [[TSAlertOverlayWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
ow.alpha = 0.0;
ow.backgroundColor = [UIColor clearColor];
ow.rootViewController = avc;
[ow makeKeyAndVisible];
// fade in the window
[UIView animateWithDuration: 0.2 animations: ^{
ow.alpha = 1;
}];
// add and pulse the alertview
// add the alertview
[avc.view addSubview: self];
[self sizeToFit];
self.center = CGPointMake( CGRectGetMidX( avc.view.bounds ), CGRectGetMidY( avc.view.bounds ) );;
self.frame = CGRectIntegral( self.frame );
[self pulse];
if ( self.style == TSAlertViewStyleInput )
{
[self layoutSubviews];
[self.inputTextField becomeFirstResponder];
}
}
と
@interface TSAlertOverlayWindow : UIWindow
{
}
@property (nonatomic,retain) UIWindow* oldKeyWindow;
@end
@implementation TSAlertOverlayWindow
@synthesize oldKeyWindow;
- (void) makeKeyAndVisible
{
self.oldKeyWindow = [[UIApplication sharedApplication] keyWindow];
self.windowLevel = UIWindowLevelAlert;
[super makeKeyAndVisible];
}
- (void) resignKeyWindow
{
[super resignKeyWindow];
[self.oldKeyWindow makeKeyWindow];
}
//
@end