Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调整iPhone键盘窗口的大小';主视图_Iphone_Objective C - Fatal编程技术网

调整iPhone键盘窗口的大小';主视图

调整iPhone键盘窗口的大小';主视图,iphone,objective-c,Iphone,Objective C,编辑2:当我在顶部没有状态栏的情况下启动应用程序时,一切都按计划进行。有了状态栏,我无法让视图按我所希望的方式运行。看起来UINavigationController通过减去状态栏的20个像素来不断调整内容视图的大小。我不知道 我创建了一个简单的基于UINavigationController的应用程序。此导航控制器中的根视图是UITableView。在某个特定时间,我想从底部在80像素高的视图中滑动。顶部的整个视图(由UINavigationController控制的视图)应调整大小并缩小80

编辑2:当我在顶部没有状态栏的情况下启动应用程序时,一切都按计划进行。有了状态栏,我无法让视图按我所希望的方式运行。看起来UINavigationController通过减去状态栏的20个像素来不断调整内容视图的大小。我不知道

我创建了一个简单的基于UINavigationController的应用程序。此导航控制器中的根视图是UITableView。在某个特定时间,我想从底部在80像素高的视图中滑动。顶部的整个视图(由UINavigationController控制的视图)应调整大小并缩小80像素,以便为新的底部视图腾出空间

这基本上就是我用来重新定位视图的代码:

-(void)showTeaser {
float adHeight = 80;

[adView setFrame:CGRectMake(0.0,self.navigationController.view.bounds.size.height, 320.0, 80.0)];
[[[UIApplication sharedApplication] keyWindow] addSubview:adView];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[adView setAlpha:1.0];
[adView setFrame:CGRectMake(0.0,self.navigationController.view.bounds.size.height-adHeight, 320.0, 80.0)];
[self.navigationController.view setFrame:CGRectMake(0.0,0.0, 320.0, self.navigationController.view.bounds.size.height-adHeight)]; 

[self.view setFrame:CGRectMake(0.0, 0, 320.0, self.view.bounds.size.height-adHeight)]; 

[UIView commitAnimations]; }
我降低了导航栏的alpha,将UITableviewController的视图设置为红色。新的景色是紫色的

事情就是这样。第一个屏幕截图初始状态。一切看起来都很正常。第二个屏幕截图显示更改帧后的状态。UITableviewController的视图始终在导航栏下按20像素。此外,如果我尝试向keywindow添加更多视图,它们最终总是比我预期的高20像素。它看起来几乎像是将keywindow(减去导航栏)向上推了20个像素

编辑1:无论我调整视图的大小,它总是20像素

将视图添加到keywindow是否犯了错误?我不应该这样做吗


您是否尝试过使用tableview的transform属性而不是手动更改其帧?这可能会更好,因为帧取决于原点,您只想更改它的大小。

为了解决这个问题,我将
UINavigationController
的视图设置为
UIView
的子视图,并手动设置“UINavigationController”的视图边界

//outerView is a UIView defined in the interface
outerView = [[UIView alloc] initWithFrame:CGRectMake( 0.0, 0.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);]; 

//mainNavigationController is a UINavigationController defined in the interface
//rootViewController is a UIViewController (or inherited class) defined in the interface and instanced before this code
mainNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

//set the frame for the view of the navigation controller - 20 is due to the status bar
mainNavigationController.view.frame = CGRectMake( 0.0, 20.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20);
然后,当我稍后调整大小时,我会调整父级“UIView”而不是“UINavigationController”视图的大小

//change the outer view's frame to resize everything
//adHeight is a float defined earlier
outerView.frame = CGRectMake( 0.0, 20.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20 - adHeight);
这在动画序列中效果很好


编辑2011-05-12:我更新了
外部视图
框架以填充屏幕。这必须设置为允许触摸事件。

我已经使用了TableViewController视图的自动调整大小遮罩,但这并没有改变基本问题。