Отображение картинки в ландшафтном режиме на весь экран - PullRequest
0 голосов
/ 21 сентября 2010

Я добавил небольшой код для показа изображений, но почему картинка в портретном режиме оптимизирована для экрана 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];
}

1 Ответ

1 голос
/ 21 сентября 2010

Когда iPhone вращается, обычно матрица аффинного преобразования содержит преобразование, необходимое для вращения. Это означает, что с вашим кодом преобразование для представления изменяется так, как оно поворачивается, но, поскольку вы поворачиваете изображение, вы поворачиваете его назад.

попробуйте это:

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