开发者

Autorotation with navigation back button

开发者 https://www.devze.com 2023-04-02 03:54 出处:网络
I am creating an app which support all orientation. I am using navigationController here. for orientation i am using this code

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).


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;
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消