我有自己的自定义UIViewController,它包含一个带有UIImageView的UIScrollView作为它的子视图.我希望在设备方向改变时使图像自动旋转,但它似乎不起作用......
在头文件中,我有;
@interface MyViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *containerView;
UIImageView *imageView;
}
Run Code Online (Sandbox Code Playgroud)
这些组件在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];
Run Code Online (Sandbox Code Playgroud)
我添加了以下方法,假设我需要使视图自动旋转...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
MyViewController加载了我指定从URL中获取的图像,并且当我翻转设备时,正在调用shouldAutorotate ...函数和正确的UIInterfaceOrientation.
但是,didRotateFromInterfaceOrientation方法没有被调用,并且图像似乎没有自行旋转...有人可以指出我需要添加什么,或者我在这里做错了什么?
提前致谢!