【问题标题】:Show a different image based on presenting view controller and orientation根据呈现的视图控制器和方向显示不同的图像
【发布时间】:2013-02-02 04:30:10
【问题描述】:

我从其他几个人那里展示了这个视图控制器。如何根据不同的图像呈现不同的图像

  1. 哪个视图控制器呈现了这个
  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];
    }

【问题讨论】:

  • 问题是我如何以及在哪里实现 if/only 语句以使其工作?
  • 我是目标 c 的新手 :(

标签: ios objective-c


【解决方案1】:

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

【讨论】:

  • +1 那,或者让每个呈现控制器在ContextualController 中设置一个属性,告诉它使用什么图像。这不是额外的工作,它为让呈现控制器根据情况选择不同的图像敞开了大门。
  • 谢谢大家的提示,如果可能的话,你能举个例子吗?我在这方面有点新意
猜你喜欢
  • 1970-01-01
  • 2018-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多