0

我实现了一个小代码来显示图片,但是为什么纵向模式下的图片针对 iPhone 屏幕进行了优化,而在横向模式下没有优化,请您帮帮我,这里是代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
        imageView.frame = CGRectMake(0, 0, 320, 480); 
        imageView.contentMode = UIViewContentModeScaleToFill;
        return YES;
    } else if((interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) { 
        imageView.contentMode = UIViewContentModeScaleToFill;
        imageView.frame = CGRectMake(0, 0, 480, 320); 
        return YES;
    }
    return YES;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [self ladeImage];

    [super viewDidLoad];
}

- (void)ladeImage {
    id path = @"http://172.23.1.63:8080/RestfulJava/pics";
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];  
    UIImage *img = [[UIImage alloc] initWithData:data];
    imageView = [[UIImageView alloc] initWithImage:img];
    imageView.frame = self.view.frame;
    [self.view addSubview:imageView];
}
4

1 回答 1

1

当 iPhone 旋转时,通常仿射变换矩阵包含旋转所需的变换。这意味着,使用您的代码,视图的转换会以旋转的方式进行更改,但是由于您也旋转了图像,因此您将其旋转回来。

试试这个:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return YES;
}
于 2010-09-21T09:57:33.523 回答