gpt4 book ai didi

ios - 根据呈现 View Controller 和方向显示不同的图像

转载 作者:行者123 更新时间:2023-11-29 04:09:27 24 4
gpt4 key购买 nike

我展示了其他几个 View Controller 。我怎样才能呈现不同的图像基于

  1. 哪个 View Controller 呈现了这个
  2. 当前界面方向

现在,我有一个在 ContextualController 上方打开的按钮,其中包含屏幕尺寸图像。我想根据我在三个不同的 UIViewControllers 中按下按钮的位置来调用不同的图像。

UIViewController1我想调用context_1_landscapecontext_1_portrait。我想从 UIViewController2 调用 context_2_landscapecontext_2_portrait

-(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];
}

最佳答案

您可以使用 UIViewControllerpresentingViewController 属性找出向您介绍的人。我的建议是让每个presentingViewControllers都有一个属性,即要显示的图像名称(或图像本身)。然后在 viewDidLoad 中,您要求 presentingViewController(转换为相应类的对象)提供用于纵向或横向的图像。

关于ios - 根据呈现 View Controller 和方向显示不同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14652025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com