iPhone - 当设备方向改变时 UIViewController 不旋转

标签 iphone cocoa-touch

我有自己的自定义 UIViewController,其中包含一个 UIScrollView 和一个 UIImageView 作为它的 subview 。我想让图像在设备方向改变时自动旋转,但它似乎不起作用......

在头文件中,我有;

@interface MyViewController : UIViewController <UIScrollViewDelegate> {
    IBOutlet UIScrollView   *containerView;
    UIImageView *imageView;
}

这些组件在 loadView 函数中初始化,如下所示;

    containerView = [[UIScrollView alloc] initWithFrame:frame];

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://..."]];
    UIImage *image = [[UIImage alloc] initWithData:data];
    imageView = [[UIImageView alloc] initWithImage:image];
    [image release];

    [containerView addSubview:imageView];

我添加了以下方法,假设这就是使 View 自动旋转所需的全部...

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

当我翻转设备时,MyViewController 可以很好地加载我指定从 URL 抓取的图像,并且使用正确的 UIInterfaceOrientation 调用 shouldAutorotate... 函数。

但是,didRotateFromInterfaceOrientation 方法不会被调用,并且图像似乎不会自行旋转... 有人可以指出我需要添加什么,或者我在这里做错了什么吗?

提前致谢!

最佳答案

这对你来说可能不是正确的答案,因为你没有指定 UIViewController 所在的上下文,但我刚刚在 Apple 文档中发现了一个重要的问题,它解释了我遇到的类似问题。

Tab bar controllers support a portrait orientation by default and do not rotate to a landscape orientation unless all of the root view controllers support such an orientation. When a device orientation change occurs, the tab bar controller queries its array of view controllers. If any one of them does not support the orientation, the tab bar controller does not change its orientation.

关于iPhone - 当设备方向改变时 UIViewController 不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/432793/

相关文章:

iphone - 模拟 iPhone 和 iPod Touch 收件箱编辑模式(红色复选标记,蓝色背景)

iphone - iOS海量数据的高效存储

objective-c - 将 pdf 页面保存在多页数组中

ios - 使用 KVC 从 NSMutableArray 获取 NSMutableDictionary

iphone - UITableView滚动到特定位置

iphone - 编写适用于 iOS 和 Mac OS 的类

ios - 观察类中静态变量的值?

iphone - 为什么我的 tableView 是空白的?我没有正确地重新加载我的数据源吗?

iphone - if else 语句混淆 Objective-C

iphone - 如何在 iPhone 上改变 View 时制作溶解动画?