在启动期间出现设备方向和UIView问题

我正在开发一个项目,当用户按下按钮时将播放video,我必须为所有方向编写此应用程序。 我添加了图像作为按钮的背景,根据超视图的大小给出了这些按钮的位置,如下所示:

button1.frame = CGRectMake(0.15 * (self.view.frame.size.width),0.15 * (self.view.frame.size.height), 0.2 * (self.view.frame.size.width), 0.2 * (self.view.frame.size.height)); 

当我以纵向启动应用程序时,它的视图很好,而且当我旋转它时工作正常:

截图肖像

但如果我在横向启动我的应用程序,它会显示如下视图:

截图景观

我使用了大量代码来调整视图和子视图的大小:

 -(void) viewDidLoad { ... self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self.view setAutoresizesSubviews:YES]; button1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; ... } 

在didRotateFromInterfaceOrientation()和willRotateToInterfaceOrientation()中:

 ... self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self.view setAutoresizesSubviews:YES]; button1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; ... 

我还在shouldAutoRotate()中返回指定YES。 我在这里缺少什么? 任何帮助将不胜感激。

  you have to declaration below and all give them in viewDidLoad but frame give in this code -(void)viewWillAppear:(BOOL)animated { [self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:1.0]; UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) { [self setFrameForLeftAndRightOrientation]; } else if(orientation == UIInterfaceOrientationPortrait ) { [self setFrameForPortraitAndUpsideDownOrientation]; } } - (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { [self setFrameForLeftAndRightOrientation]; } else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { [self setFrameForPortraitAndUpsideDownOrientation]; } } -(void)setFrameForLeftAndRightOrientation { if(IS_IPAD) { } else if(IS_IPHONE) { if ([[UIScreen mainScreen] bounds].size.height == 568) { } else { } } } -(void)setFrameForPortraitAndUpsideDownOrientation { if(IS_IPAD) { } else if(IS_IPHONE) { if ([[UIScreen mainScreen] bounds].size.height == 568) { } else { } } }