gpt4 book ai didi

ios - 我的工具栏不会显示在 webView 上方

转载 作者:行者123 更新时间:2023-11-29 10:45:29 28 4
gpt4 key购买 nike

我正在尝试将工具栏添加到我的 View Controller 。

我的 View Controller :

-(void)loadView
{
UIWebView *webView = [[UIWebView alloc]init];
webView.scalesPageToFit = YES;
self.view = webView;

UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0,self.view.bounds.size.height-50, self.view.bounds.size.width, 50);
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStyleDone target:self action:@selector(sendAction)];

UIBarButtonItem *button2=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];

[toolbar setItems:[[NSArray alloc] initWithObjects:button1, nil]];
[toolbar setItems:[[NSArray alloc] initWithObjects:button2, nil]];
[self.view addSubview:toolbar];
}

工具栏不会显示。

我应该避免:

 self.view = webView;

只需设置 self.view 的框架,然后将 webView 添加为 subview ?

最佳答案

你在这行计算错误:

toolbar.frame = CGRectMake(0,self.view.bounds.size.height-50, self.view.bounds.size.width, 50);

您已将 View 的 Y 位置设置为比 View 高度小 50 个单位。这会起作用,但是此时 self.view.frame 尚未正确计算并包含 (0,0,0,0) 矩形。最好使用 AutoLayout,但一个简单/hacky 的解决方案如下:

CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
toolbar.frame = CGRectMake(0,mainScreenFrame.size.height-50, self.view.bounds.size.width, 50);

关于ios - 我的工具栏不会显示在 webView 上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22567554/

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