在每一个人中,我都面临着有关UIImageView contentMode的问题。我正在使用以下代码来调整imageView中的图像。
CGSize imageSize=imageView.image.size;
UIInterfaceOrientation orientation=[UIApplication sharedApplication].statusBarOrientation;
if (imageSize.width>imageSize.height) { //land scape image
if (orientation ==UIInterfaceOrientationLandscapeLeft || orientation==UIInterfaceOrientationLandscapeRight) { //device in landscape mode
[imageView setContentMode:UIViewContentModeScaleAspectFill];
}
else //device in potriate moded
{
[imageView setContentMode:UIViewContentModeScaleAspectFit];
}
}
else //potrial image
{
if (orientation ==UIInterfaceOrientationLandscapeLeft || orientation==UIInterfaceOrientationLandscapeRight) { //device in landscape mode
[imageView setContentMode:UIViewContentModeScaleAspectFit];
}
else //device in potriate moded
{
[imageView setContentMode:UIViewContentModeScaleAspectFill];
}
}
当我在viewDidLoad方法中调用它时,代码工作正常,但是当我尝试在viewWillAppear方法中调用它时,它无效。我想在viewWillAppear中使用它,所以请告诉我解决方案谢谢。