【发布时间】:2009-01-11 11:51:50
【问题描述】:
我有我自己的自定义 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 中获取的图像,并且当我翻转设备时,将使用正确的 UIInterfaceOrientation 调用 shouldAutorotate... 函数。
但是,没有调用 didRotateFromInterfaceOrientation 方法,并且图像似乎没有自行旋转...... 有人可以指出我需要添加什么,或者我在这里做错了什么吗?
提前致谢!
【问题讨论】:
标签: iphone cocoa-touch