Ios 中心视图不显示';行不通

Ios 中心视图不显示';行不通,ios,view,uiview,orientation,Ios,View,Uiview,Orientation,我尝试将显示在我的iPad应用程序中的视图居中,这取决于界面方向。 这不起作用,视图总是根据应用程序启动的方向而改变 我已经在Stackoverflow中搜索了2个小时,尝试了不同的方法,但都没成功 以下是从根视图显示视图的方式: publicationDownload = [[PublicationDownloadController alloc] init]; // Setting up propertys to load Publication-related information [p

我尝试将显示在我的iPad应用程序中的视图居中,这取决于界面方向。 这不起作用,视图总是根据应用程序启动的方向而改变

我已经在Stackoverflow中搜索了2个小时,尝试了不同的方法,但都没成功

以下是从根视图显示视图的方式:

publicationDownload = [[PublicationDownloadController alloc] init];
// Setting up propertys to load Publication-related information
[publicationDownload setDelegate:self];
[publicationDownload setThePubID:[NSNumber numberWithInt:[sender tag]]];

publicationDownload.view.opaque = NO;
publicationDownload.view.backgroundColor = [UIColor clearColor];
[publicationDownload.theUIView.layer setCornerRadius:5];
[publicationDownload.theUIView.layer setShadowColor:[UIColor blackColor].CGColor];
[publicationDownload.theUIView.layer setShadowOpacity:0.5];
[publicationDownload.theUIView.layer setShadowRadius:5];
[publicationDownload.theUIView.layer setShadowOffset:CGSizeMake(3.0f, 3.0f)];
publicationDownload.theUIView.clipsToBounds = NO;
publicationDownload.theUIView.backgroundColor = [UIColor clearColor];
[publicationDownload.theInnerUIView.layer setCornerRadius:5];
[publicationDownload.theInnerUIView.layer setShadowColor:[UIColor blackColor].CGColor];
[publicationDownload.theInnerUIView.layer setShadowOpacity:0.5];
[publicationDownload.theInnerUIView.layer setShadowRadius:5];
[publicationDownload.theInnerUIView.layer setShadowOffset:CGSizeMake(3.0f, 3.0f)];
[publicationDownload.theInnerUIView.layer setMasksToBounds:YES];
publicationDownload.theUIView.layer.masksToBounds = NO;
publicationDownload.view.clipsToBounds = YES;
publicationDownload.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.5];

[self.view addSubview:publicationDownload.view];
在publicationDownloadViewController中,我实现了:

viewDidLoad
中: //从nib加载视图后,执行任何其他设置

//self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
//self.view.contentMode = UIViewContentModeRedraw;
self.view.autoresizesSubviews = YES;
//self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.view.frame = self.view.bounds;
//theUIView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;

NSLog(@"PublicationDownloadController: viewDidLoad:");
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];    
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    theUIView.frame = CGRectMake(212, 229, 600, 240);
    self.view.frame = CGRectMake(0, 0, 1024, 768);
} else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
    theUIView.frame = CGRectMake(140, 380, 600, 240);
    self.view.frame = CGRectMake(0, 0, 768, 1024);
}
及其他:

-(void)didRotate:(NSNotification*)notification
{
    NSLog(@"PublicationDownloadController: didRotate");
UIDeviceOrientation oreo = [[UIDevice currentDevice] orientation];
// oreo is our new orientation!
if (oreo == UIInterfaceOrientationPortrait || oreo == UIInterfaceOrientationPortraitUpsideDown) {
    //theUIView.frame = CGRectMake(212, 229, 600, 240);
    self.view.frame = self.view.bounds;
} else if (oreo == UIInterfaceOrientationLandscapeLeft || oreo == UIInterfaceOrientationLandscapeRight) {
    //theUIView.frame = CGRectMake(140, 380, 600, 240);
    self.view.frame = self.view.bounds;
}
}
视图本身包含横向视图,背景设置为黑色,alpha 0.5(在IB中)- 另外还有另一个视图(theUIView),它保存一些uicontrol。该视图需要居中。如果ste应用程序在横向视图的横向中启动,则该功能有效,但如果方向更改为纵向,则不起作用。此外,如果应用程序以纵向模式启动,则视图不会居中显示


非常感谢您的帮助

这比预期的要容易。处理Interface Builder中的autoresizemask并清理一些凌乱的代码完成了任务。

为什么不重写UIViewController类的Interface Orientation方法中的
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation方法?我这样做了,但两个方法都没有被调用。