views:

26

answers:

2

Hello People,

i implemented a small code to show pictures, but why is the picture on Portrait Mode optimized to the iPhone screen and NOT optimized in Landscape Mode could you please help me, here is the code:

-(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  A: 

When the iPhone is rotated, usually the affine transformation matrix contains the transformation needed for the rotation. This means that, with your code, the transformation for the view is changed in a way that it is rotated, but since you rotate the image too, you rotate it back.

try this:

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

Sorry but it doesn't work, i have changed the code to this one:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 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];
}

what is wrong, i am on work with this since 3 hours?

Marco