UIToolBar和iPhone界面方向问题
问题描述:
我正在iPhone上开发一个应用程序。一种观点支持纵向和横向的定位。对于这两种定位我有两个单独的视图。该视图顶部有一个UIToolbar
。UIToolBar和iPhone界面方向问题
问题是当我从风景改变回肖像时,顶部的UIToolbar
消失。当我将toolbar
旋转回肖像时,我想让它回到原来的位置。
这是我在做什么在我的程序:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform =
CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
}
我不知道我缺少什么吗?任何帮助将非常感激。
答
,如果你想只是为了让你的看法可旋转的,是足以实现
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return YES; }
在viewCountroller类
答
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
这里的问题是,你正在做的高480.但它应该是460.所以,你现在的高度已经超过了20px,这可能会使屏幕上的Toopbar稍微偏离屏幕。
答
在界面构建器中,选择工具栏,命中命令3;这将显示标尺/对齐控制菜单。
在自动调整部分下,默认情况下,工具栏仅与左右和中心耦合。不是TOP。选择顶部的“我”。现在工具栏相对于视图顶部停靠,并且在旋转过程中不会被推掉。
我敢肯定,这里还有一个相当于此的代码
+0
也有可能某些其他视图未正确锚定(在Autosizing中),并且正在将其自身绘制在工具栏上。 – jlstrecker 2011-01-28 18:22:52
另外,您还需要在Interface Builder的布局选项卡上设置锚点/拉伸设置。 – 2009-11-29 03:45:04
我有两个想要在纵向和横向模式下交换的视图。纵向视图在顶部有一个工具栏,在首次启动时显示正常。但是,当我改变方向并将其设置回肖像工具栏消失。 – Leo 2009-11-29 10:58:01