我有自己的自定义UIViewController,其中包含一个UIScrollView,并将UIImageView作为其子视图。当设备方向改变时,我想让图像自动旋转,但似乎没有起作用...
在头文件中,我有;
@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];
我已经添加了下面的方法,假设这就是我需要让视图自动旋转的全部内容...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
我已经在MyViewController中成功从指定的 URL 获取了图片,当我翻转设备时,shouldAutorotate... 函数被调用,并且 UIInterfaceOrientation 也是正确的。
然而,didRotateFromInterfaceOrientation 方法没有被调用,图片似乎也没有自动旋转。 请问有谁能指出我需要添加什么,或者我做错了什么吗?
先感谢您!