Question

i have a requirnmant for ipad to show contents both in landscape and portrait..so i have done the code and done the postions of controlles in each orientations.it works fine..my code is

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||interfaceOrientation == UIInterfaceOrientationLandscapeLeft  ) {

        _viewContainer.frame = CGRectMake(342, 1, 681, 707);
        _viewtopic.frame = CGRectMake(1, 62, 343, 56);
        _viewpublicspeekingheaderleft.frame = CGRectMake(0, 6, 341, 58);
        _viewTableview.frame = CGRectMake(1, 118, 341, 590);
        _viewFooter.frame = CGRectMake(1, 716, 1024, 48);


  if (interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown  ) {

        _viewContainer.frame = CGRectMake(276, 1, 503, 946);
        _viewtopic.frame = CGRectMake(0, 58, 275, 50);
        _viewpublicspeekingheaderleft.frame = CGRectMake(0, 1, 275, 58);
        _viewTableview.frame = CGRectMake(1, 109, 274, 837);
        _viewFooter.frame = CGRectMake(1, 954, 767, 48);

    }

    return YES;
}

the above code works fine for me,i got alla the controllers in corect postions..here is my probm,,i have to set a timer to show full screen and i need to hide some controlers in the viewcontroller,,i had done the timer set to 3 second and after 3 second it hides some controlles and arrange the othe controlers in the view controller to show the ful sceen.it also works fine for me.my code fo this is

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Define the timer object

    NSTimer *timer;

   // Create the timer object

    timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self 
                                           selector:@selector(updateorientation:) userInfo:nil repeats:NO];
}

- (void) updateorientation:(NSTimer *)incomingTimer
{

    _tableTopic.hidden =YES;
    _viewtopic.hidden =YES;
    _viewpublicspeekingheaderleft.hidden =YES;
    _viewTableview.hidden =YES;
    _imgpulbicspeakingabovethetableview.hidden =YES;
    _topiclabel.hidden =YES;
    _lblpublicspeekingleft.hidden =YES;


    UIInterfaceOrientation orientation =[[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown ) {
        NSLog(@"portrait");// only works after a rotation, not on loading app

        _imgMicimage.frame = CGRectMake(69, 130, 635, 216);
          _txtContentofTopic.frame = CGRectMake(69, 354, 635, 203);
          _viewContainer.frame = CGRectMake(0, 0, 768, 1024);


    }
    UIInterfaceOrientation orientationLandscape =[[UIApplication sharedApplication] statusBarOrientation];
    if (orientationLandscape == UIDeviceOrientationLandscapeLeft || orientationLandscape == UIDeviceOrientationLandscapeRight ) {
        NSLog(@"landscape");

        _imgMicimage.frame = CGRectMake(93, 113, 836, 239);
        _txtContentofTopic.frame = CGRectMake(93, 360, 836, 203);
        _viewContainer.frame = CGRectMake(0, 0, 1024, 768);

    }
    }

it works fine,but after the timer fires ,then i chnage the orientation of the device ,i only get the arrangmnts in the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { function.i need the arrangmnts in the time function.how to solve this.

thanks in advance.

}

Was it helpful?

Solution

You should not be doing this work in -shouldAutorotateToInterfaceOrientation:. That method is simply to determine whether your UI should rotate (and will soon be superceded by a new system). You should use these methods to lay out your UI in reaction to an actual rotation:

  • -willRotateToInterfaceOrientation:duration:
  • -willAnimateRotationToInterfaceOrientation:duration:
  • -didRotateFromInterfaceOrientation:

Please see the UIViewController docs for more on those.

On iOS 5, -viewWillLayoutSubviews might be another good choice. (It will be called even if your controller's view isn't currently visible.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top