带导航后退按钮的自动旋转

发布于 2024-12-02 12:23:53 字数 3715 浏览 0 评论 0原文

我正在创建一个支持所有方向的应用程序。
我在这里使用 navigationController。
对于方向,我正在使用此代码,

- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {

if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    category1.frame = CGRectMake(54, 68, 190, 174);
    category2.frame = CGRectMake(291, 68, 190, 174);
    category3.frame = CGRectMake(525, 68, 190, 174);
    category4.frame = CGRectMake(54, 296, 190, 174);
    category5.frame = CGRectMake(291, 296, 190, 174);
    category6.frame = CGRectMake(525, 296, 190, 174);
    category7.frame = CGRectMake(54, 527, 190, 174);
    category8.frame = CGRectMake(291, 527, 190, 174);
    category9.frame = CGRectMake(525, 527, 190, 174);
    category10.frame = CGRectMake(291, 757, 190, 174);
    extra1.frame = CGRectMake(80, 781, 138, 125);
    extra2.frame = CGRectMake(551, 781, 138, 125);

}
else 
{
    category1.frame = CGRectMake(61, 50, 190, 174);
    category2.frame = CGRectMake(298, 50, 190, 174);
    category3.frame = CGRectMake(537, 50, 190, 174);
    category4.frame = CGRectMake(774, 50, 190, 174);
    category5.frame = CGRectMake(61, 278, 190, 174);
    category6.frame = CGRectMake(298, 278, 190, 174);
    category7.frame = CGRectMake(537, 278, 190, 174);
    category8.frame = CGRectMake(774, 278, 190, 174);
    category9.frame = CGRectMake(298, 509, 190, 174);
    category10.frame = CGRectMake(537, 509, 190, 174);
    extra1.frame = CGRectMake(80, 533, 120, 125);
    extra2.frame = CGRectMake(800, 533, 120, 125);

}

}

它在此视图中完美运行。当我选项卡按钮时,它会转到第二个视图控制器,我在其中显示表格视图。
但是,如果我通过导航后退按钮返回第一个视图,方向不会完美显示。
上面的代码不适用于导航后退按钮。

对于这个问题我该怎么办?
有什么建议吗?

先感谢您。

编辑:

我已从firstview 中删除了上述函数,并将代码复制到该函数中。

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
    if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    category1.frame = CGRectMake(54, 68, 190, 174);
    category2.frame = CGRectMake(291, 68, 190, 174);
    category3.frame = CGRectMake(525, 68, 190, 174);
    category4.frame = CGRectMake(54, 296, 190, 174);
    category5.frame = CGRectMake(291, 296, 190, 174);
    category6.frame = CGRectMake(525, 296, 190, 174);
    category7.frame = CGRectMake(54, 527, 190, 174);
    category8.frame = CGRectMake(291, 527, 190, 174);
    category9.frame = CGRectMake(525, 527, 190, 174);
    category10.frame = CGRectMake(291, 757, 190, 174);
    extra1.frame = CGRectMake(80, 781, 138, 125);
    extra2.frame = CGRectMake(551, 781, 138, 125);

}
else 
{
    category1.frame = CGRectMake(61, 50, 190, 174);
    category2.frame = CGRectMake(298, 50, 190, 174);
    category3.frame = CGRectMake(537, 50, 190, 174);
    category4.frame = CGRectMake(774, 50, 190, 174);
    category5.frame = CGRectMake(61, 278, 190, 174);
    category6.frame = CGRectMake(298, 278, 190, 174);
    category7.frame = CGRectMake(537, 278, 190, 174);
    category8.frame = CGRectMake(774, 278, 190, 174);
    category9.frame = CGRectMake(298, 509, 190, 174);
    category10.frame = CGRectMake(537, 509, 190, 174);
    extra1.frame = CGRectMake(80, 533, 120, 125);
    extra2.frame = CGRectMake(800, 533, 120, 125);

}

    return YES;
 }

在我的第二个视图控制器中,我已经完成了

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {

    return YES;
 }

当我通过点击导航后退按钮返回第一个视图时其他条件(横向模式)工作正常,但我不知道为什么它不能与一起使用if 条件(肖像模式)。

I am creating an app which support all orientation.
I am using navigationController here.
for orientation i am using this code

- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {

if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    category1.frame = CGRectMake(54, 68, 190, 174);
    category2.frame = CGRectMake(291, 68, 190, 174);
    category3.frame = CGRectMake(525, 68, 190, 174);
    category4.frame = CGRectMake(54, 296, 190, 174);
    category5.frame = CGRectMake(291, 296, 190, 174);
    category6.frame = CGRectMake(525, 296, 190, 174);
    category7.frame = CGRectMake(54, 527, 190, 174);
    category8.frame = CGRectMake(291, 527, 190, 174);
    category9.frame = CGRectMake(525, 527, 190, 174);
    category10.frame = CGRectMake(291, 757, 190, 174);
    extra1.frame = CGRectMake(80, 781, 138, 125);
    extra2.frame = CGRectMake(551, 781, 138, 125);

}
else 
{
    category1.frame = CGRectMake(61, 50, 190, 174);
    category2.frame = CGRectMake(298, 50, 190, 174);
    category3.frame = CGRectMake(537, 50, 190, 174);
    category4.frame = CGRectMake(774, 50, 190, 174);
    category5.frame = CGRectMake(61, 278, 190, 174);
    category6.frame = CGRectMake(298, 278, 190, 174);
    category7.frame = CGRectMake(537, 278, 190, 174);
    category8.frame = CGRectMake(774, 278, 190, 174);
    category9.frame = CGRectMake(298, 509, 190, 174);
    category10.frame = CGRectMake(537, 509, 190, 174);
    extra1.frame = CGRectMake(80, 533, 120, 125);
    extra2.frame = CGRectMake(800, 533, 120, 125);

}

}

It works perfectly in this view. when i tab button it goes to secondviewcontroller where i am showing tableview.
But , if i go back to the firstview via navigation back button ,the orientation is not showing perfectly.
Above code is not working for navigation back button.

What should i do for this problem??
Any suggestion ??

Thank you in advance.

Edited:

I have removed my above function from firstview and copy the code to this function.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
    if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    category1.frame = CGRectMake(54, 68, 190, 174);
    category2.frame = CGRectMake(291, 68, 190, 174);
    category3.frame = CGRectMake(525, 68, 190, 174);
    category4.frame = CGRectMake(54, 296, 190, 174);
    category5.frame = CGRectMake(291, 296, 190, 174);
    category6.frame = CGRectMake(525, 296, 190, 174);
    category7.frame = CGRectMake(54, 527, 190, 174);
    category8.frame = CGRectMake(291, 527, 190, 174);
    category9.frame = CGRectMake(525, 527, 190, 174);
    category10.frame = CGRectMake(291, 757, 190, 174);
    extra1.frame = CGRectMake(80, 781, 138, 125);
    extra2.frame = CGRectMake(551, 781, 138, 125);

}
else 
{
    category1.frame = CGRectMake(61, 50, 190, 174);
    category2.frame = CGRectMake(298, 50, 190, 174);
    category3.frame = CGRectMake(537, 50, 190, 174);
    category4.frame = CGRectMake(774, 50, 190, 174);
    category5.frame = CGRectMake(61, 278, 190, 174);
    category6.frame = CGRectMake(298, 278, 190, 174);
    category7.frame = CGRectMake(537, 278, 190, 174);
    category8.frame = CGRectMake(774, 278, 190, 174);
    category9.frame = CGRectMake(298, 509, 190, 174);
    category10.frame = CGRectMake(537, 509, 190, 174);
    extra1.frame = CGRectMake(80, 533, 120, 125);
    extra2.frame = CGRectMake(800, 533, 120, 125);

}

    return YES;
 }

in my second view controller i have done

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {

    return YES;
 }

When i go back to the firstview by tapping navigation back button else condition(landscape mode) works fine but i don't know why it is not working with if condition(Portraitmode).

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

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

发布评论

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

评论(1

束缚m 2024-12-09 12:23:53

将所有这些代码写入以下函数中。

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
        //set all the frames according to the current interface orientation
        return YES;
 }

新编辑:

将此方法写入您的detailviewcontroller.m 文件中

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
        UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:0];
        [controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];

        return YES;
  }

Write all this code in the following function.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
        //set all the frames according to the current interface orientation
        return YES;
 }

NEW EDIT :

Write this method into your detailviewcontroller.m file

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
        UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:0];
        [controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];

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