iphone - 横向和纵向 View 中的旋转问题

标签 iphone objective-c ios

在我的应用程序中,我有 2 个 View ,portraitView 和 landScapeView。而且我的应用程序包含许多 View ...

  1. 当我启动应用程序时,横向和纵向 View 并排显示。

  2. 当我在横向 View 中启动应用程序时,会显示纵向 View 。稍后在旋转并返回后 View 会变得正确。

下面给出了我正在使用的代码...所以请建议我应该做哪些更改来克服上述问题..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{ 

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {  
    NSLog(@"LANDSCAPE>>");
    portraitView.hidden = YES;
    landscapeView.hidden = NO;

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]];
    self.view.backgroundColor = background;



}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
    NSLog(@"LANDSCAPE<<");
    portraitView.hidden = YES;
    landscapeView.hidden = NO;
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]];
    self.view.backgroundColor = background;

    self.view.hidden = NO;

}
else{
    portraitView.hidden = NO;
    landscapeView.hidden = YES;


    NSLog(@"Portrait");
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic.jpg"]];
    self.view.backgroundColor = background;

    background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic2.jpg"]];
  self.view.backgroundColor = background;

}

return YES;

最佳答案

听起来您的 portraitView 和 landscapeView 在应用程序初始启动时都可见。上面的代码仅在运行时方向改变时执行。如果您确实坚持为纵向和横向使用单独的 View ,那么您还需要在启动时检测方向并适本地显示/隐藏 View 。

关于iphone - 横向和纵向 View 中的旋转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7792823/

相关文章:

iphone - iOS 上的代码路径

ios - 使用 Objective-C 将 JSON 反序列化为自定义对象

ios - swift +异步: How to execute a callback on the same thread where it was created?

ios - xamarin 中的帧偏移

javascript - 如何从 JavaScript 调用 Objective-C 方法?

iphone - 适用于 iOS 和 Android NDK 的 C++ 日志记录框架

iphone - 使用 iPhone 中的自定义按钮执行 MFMessageComposeViewController 中的按钮操作

ios - 将对象重写为另一个 NSMutableArray

iphone - 将图像分配给 UIImageView iPhone 时出现问题

ios - 将 AppDelegate Shared 实例设置为 nil 不会产生警告或崩溃