2012-01-12 77 views
0

我必须为相应的方向显示两个不同的图像。我通过使用Nib文件在一个UIImageView中添加了两个图像。我想在iPad方向纵向中显示image1.png,并且想要在方向横向模式下显示image2.png。任何人都可以请我建议如何在UIViewController中通过Nib文件添加两个UIImageView?请为iPad笔尖文件提供任何教程。提前致谢。如何使用Nib文件在UIViewController中添加两个UIImageView?

回答

1

你必须改变的UIImageView的图像中的视图控制器的shouldAutorotate方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) && (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) { 
    // Set image in landscape mode 
    [imageView setImage:[UIImage imageNamed:@"image1.png"]]; 
} 
else 
    // Set image in portrait mode 
    [imageView setImage:[UIImage imageNamed:@"image2.png"]]; 
} 

}

我希望它能帮助你:)

+0

Dont't忘记在结束 – 2012-01-12 14:31:47

+0

其真正返回YES!谢谢 :) – damacri86 2012-01-16 12:05:11

1

刚刚从拖动的UIImageView图书馆并放入您的视野。 但是,如果您使用的是一个UIViewController和一个视图,则需要处理代码中的图像视图旋转更改。最简单的方法 - 显示/隐藏取决于方向。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    UIImageView *landscapeimageView = nil; 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){ 
     landscapeImageView.hidden = NO; 
     portretOmageView.hidden = YES; 
    } 
    else{ 
     landscapeImageView.hidden = YES; 
     portretOmageView.hidden = NO; 
    } 
} 

您也可以只使用一个的UIImageView和image属性更改为需要的图像:

[imageView setImage:[UIImage imageNamed:@"image1.png"]];//or @"image2.png" 
相关问题