【问题标题】:iOS : How To Make Static or Fix Background on View ControlleriOS:如何在视图控制器上制作静态或修复背景
【发布时间】:2013-09-10 13:57:24
【问题描述】:

我有 2 个 ViewController,它们的 .m 文件中都有这段代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]];

}

我在两个 ViewController 之间进行了推送转换。所以当它在我的 iPod 上运行时,它看起来像第二个背景从右向左推第一个背景。

但这不是我想要的,因为两个 ViewController 的背景是相同的。我只需要在 ViewControllers 1 上移动 UI 组件(按钮、文本字段、标签等),而不是在转换运行时移动背景。

当来自 ViewControllers 2 的 UI 组件滑入时。只有组件滑入。

如何执行此操作?谢谢。。

【问题讨论】:

    标签: iphone ios objective-c


    【解决方案1】:

    试试这个:

    [self.navigationController.view setBackgroundColor:<#(UIColor *)#>]
    

    并在您的视图控制器上清除背景:

    [self.view setBackgroundColor:[UIColor ClearColor]
    

    【讨论】:

      【解决方案2】:

      当第一个视图控制器加载时,添加背景作为 window 的子视图插入到视图控制器的视图后面。然后使视图控制器视图透明。有两件事要考虑:确保你持有对它的引用,这样你就可以在视图控制器被解除时删除背景。其次,这个背景不会随着视图控制器视图自动旋转。

      现在,这就是对您问题的直接回答。如果你能按照 incmiko 的建议得到你想要的,你会是最好的。

      【讨论】:

        【解决方案3】:

        您不必使用 2 个 ViewController。使用一个,并将您的 UI 组件添加到两个视图中。然后用动画移动它们。

        将两个视图添加到您的 ViewController。将“第一个 ViewController”UI 组件添加到其中一个,然后将“第二个 ViewController”UI 组件添加到另一个。用动画移动它们,比如你的序列。你可以用这个:

         [UIView animateWithDuration:0.6 delay:0.
         options:UIViewAnimationOptionCurveEaseInOut animations:^{
        
              firstView.center = CGPointMake(Pointx, Pointy);
              secondView.center = CGPointMake(Pointx2, Pointy2);
        
              } completion:nil];
        

        【讨论】:

        • 嗨,Incmiko,我想澄清一下你的建议。你的意思是,在我的 Storyboard 上,我只有 1 个 ViewController,但我必须添加多个“视图”组件 (UIView),这样我才能执行我想要的操作?是这个意思吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多