【问题标题】:Display ViewController as PopUpSubview?将 ViewController 显示为 PopUpSubview?
【发布时间】:2012-02-07 06:26:29
【问题描述】:

我有一个带有 xib、.h、.m 文件的 ViewController。现在我想将它显示为另一个 viewController 中的 popUpView。所以我确实喜欢这个......

Second *view2 = [[Second alloc] initWithNibName:@"Second" bundle:nil];
[view2.view setFrame:CGRectMake(20, 20, 280, 400)];
{self.view addSubview:view2.view];

但这里的问题是我可以随机设置框架,但是 viewController 包含一个 textField 和按钮。它们不会被添加到视图上的随机位置,就像某些 textField 从添加的视图框架中出来一样。

经过一番谷歌搜索后,我发现了这个,但这不足以解决我的问题。

Adding a ViewConroller's View as subview programmatically

如何解决...

【问题讨论】:

  • 嗨,你的 ViewController 是做什么的?这是一个登录/通过弹出窗口?

标签: iphone uiviewcontroller popup subview popupwindow


【解决方案1】:

您似乎正在更改视图控制器中的视图框架,但没有处理视图内元素的重新定位。您可以做的是覆盖视图中的 layoutSubviews 方法,以便在框架更改时重新定位文本字段。

您必须创建一个实际的 UIView 子类来布局文本字段,

@interface SecondView : UIView{

}

@implementation SecondView{
    - (void) layoutSubviews{
      //self.frame would be to most up-to-date frame that you just set
    }
}

您的 UIViewController 将像这样创建视图,

@interface Second : UIViewController{    
}


@implementation Second{
    - (void) loadView{
        self.view = [[[SecondView alloc] init] autorelease];
    }
}

【讨论】:

    猜你喜欢
    • 2016-09-03
    • 2023-03-05
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    相关资源
    最近更新 更多