UIToolBar 和 iPhone 界面方向问题

发布于 2024-08-12 17:38:13 字数 1703 浏览 6 评论 0原文

我正在 iPhone 上开发一个应用程序。一个视图支持纵向和横向方向。我对两个方向都有两个单独的视图。该视图的顶部有一个UIToolbar

问题是当我将视图从横向更改回纵向时,顶部的 UIToolbar 消失了。我希望工具栏在旋转回纵向时返回到其原始位置。

这就是我在程序中所做的:

- (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);
    }
}

我不知道我在这里错过了什么?任何帮助将不胜感激。

I am developing an application in iPhone. One view support orientation in portrait and landscape. I have two separate views for both orientation. This view has a UIToolbar at the top.

Problem is when I change view back from landscape to portrait, UIToolbar at the top disappears. I want the toolbar to come back in its original position when it is rotated back to portrait.

This is what I am doing in my program:

- (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);
    }
}

I don't know what am I missing here? Any help would be really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

℉絮湮 2024-08-19 17:38:13

在界面生成器中,选择工具栏,点击command-3;这将打开标尺/对齐控制菜单。

在“Autsizing”部分下,默认情况下工具栏仅与左右和中心耦合。不去TOP。选择顶部的“I”。现在工具栏相对于视图顶部停靠,并且在旋转过程中不会被推开。

我确信也有一个等效的代码

In interface builder, select the toolbar, hit command-3; this brings up the ruler / alignment control menu.

Under the Autsizing section, by default the toolbar is only coupled with left-right and center. Not to the TOP. Select the "I" at the top. now the tool bar is docked relative to the top of the view and will not get pushed off during rotation.

I'm sure there is a code equivalent for this as well

随梦而飞# 2024-08-19 17:38:13

如果你只想让你的视图可旋转,就足以实现

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    返回是;
}

在你的视图Countroller类中

if you want just to make your view rotatable, is is enough to implement

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}

in your viewCountroller class

提赋 2024-08-19 17:38:13
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);  

这里的问题是您将高度设置为 480。但它应该是 460。因此您当前的高度多了 20px,这可能会使顶部栏稍微偏离屏幕。

self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);  

The problem here is that you are making the heigh 480. But it should be 460. So you are currently having 20px more on the height, which may be sending the toopbar somewhat off the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文