Ios 根据显示视图控制器和方向显示不同的图像
我从其他几个方面介绍了这个视图控制器。如何根据不同的图像呈现不同的图像Ios 根据显示视图控制器和方向显示不同的图像,ios,objective-c,Ios,Objective C,我从其他几个方面介绍了这个视图控制器。如何根据不同的图像呈现不同的图像 哪个视图控制器显示了这一个 当前接口方向 现在我有一个按钮,在ContextualController上方打开,屏幕大小为图像。 我想根据我在三个不同的UIViewControllers中按下按钮的位置调用不同的图像 从UIViewController1我想调用context\u 1\u scape和context\u 1\u trait。从UIViewController2我想调用context\u2\u-scape和co
ContextualController
上方打开,屏幕大小为图像。
我想根据我在三个不同的UIViewControllers
中按下按钮的位置调用不同的图像
从UIViewController1
我想调用context\u 1\u scape
和context\u 1\u trait
。从UIViewController2
我想调用context\u2\u-scape
和context\u2\u-trait
-(void) viewDidLoad;
{
[super viewDidLoad];
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft)|| (self.interfaceOrientation ==UIDeviceOrientationLandscapeRight)){
UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"context_1_landscape.png"]];
[self.view addSubview:imageview];
}
else if ((self.interfaceOrientation ==UIDeviceOrientationPortrait)||(self.interfaceOrientation ==UIDeviceOrientationPortraitUpsideDown)){
UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"context_1_portrait.png"]];
[self.view addSubview:imageview];
}
您可以使用
UIViewController
的presentingViewController
属性找出是谁向您演示的。我的建议是让每个PresentingViewController都有一个属性,即要显示的图像名称(或图像本身)。然后在viewdiload
中,您要求presentingViewController
(投射到适当类别的对象)提供用于纵向或横向的图像。问题是如何以及在何处实现if/only语句以实现该功能?我对目标c不熟悉:(+1,或者让每个演示控制器在ContextualController
中设置一个属性,告诉它要使用什么图像。这不需要额外的工作,而且它为演示控制器根据情况选择不同的图像打开了大门。谢谢大家的提示。如果可能的话,你能举个例子吗。我在这方面有点新手