I need to display different size of a UIImage depending on the UIInterfaceOrientation. Now the problem is, everytime the program changes its orientation the image is still there and the new one is overlapping it. Here's what I have
UIView *logoView;
UIImage *image = [UIImage imageNamed:@"pic.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[logoView removeFromSuperview];
CGRect rect;
UIInterfaceOrientation newOrientation = [UIApplication sharedApplication].statusBarOrientation;
if(newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight)
{
rect = CGRectMake(0, 0, self.view.bounds.size.width/2, self.view.bounds.size.height/4);
logoView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width/2, self.view.bounds.size.height/4)];
}
else if (newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
rect = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height/4);
logoView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width, self.view.bounds.size.height/4)];
}
imageView.frame = logoView.bounds;
[logoView addSubview:imageView];
[self.view addSubview:logoView];
Aucun commentaire:
Enregistrer un commentaire