Iphone device rotation

All my widths, heights, positions, and all are set relative to views, etc., so if the iphone is rotated, it must "expand to fit." :)

How can I say that the iphone is in "landscape mode", that is: update, but now all widths are heights, and all heights are widths?

Thanks tom

EDIT Here is the code that I currently have ... it still doesn't work - I can't figure out how to make it work

In my view, the controller (and not the root view controller) I have this method:

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

(I also tried putting this method in my root controller , but that didn't work either)

Then in my method viewDidLoad, I have the following:

[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[self.view setAutoresizesSubviews:YES];

.:( , .

+2
3

AutoresizingMask , .

layoutSubViews.

, shouldAutorotateToInterfaceOrientation viewControllers. .

  • root ViewController shouldAutorotateToInterfaceOrientation
  • viewController YES, willRotateToInterfaceOrientation
  • AutoresizingMask
  • view autoresizesSubviews true, subviews
  • didRotateToInterfaceOrientation .

viewController

- (void)loadView {
    UIView* theView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    theView.backgroundColor = [UIColor blueColor];

    UIView* redRectangle = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 100.0f, 100.0f)];
    redRectangle.tag = 1;
    redRectangle.backgroundColor = [UIColor redColor];
    [theView addSubview:redRectangle];
    [redRectangle release];

    UIView* greenRectangle = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 120.0f, 100.0f, 100.0f)];
    greenRectangle.tag = 2;
    greenRectangle.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    greenRectangle.backgroundColor = [UIColor greenColor];
    [theView addSubview:greenRectangle];
    [greenRectangle release];

    UIView* yellowRectangle = [[UIView alloc] initWithFrame:CGRectMake(theView.bounds.size.width-110.0f, theView.bounds.size.height-110.0f, 100.0f, 100.0f)];
    yellowRectangle.tag = 3;
    yellowRectangle.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
    yellowRectangle.backgroundColor = [UIColor yellowColor];
    [theView addSubview:yellowRectangle];
    [yellowRectangle release];

    self.view = theView;
    [theView release];
}

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

, :

[ tmpView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ];

, , .

, , . , , ( ), :

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    [ self refreshLayouts ];

}

refreshLayouts /, .

!

0

, :

-willRotateToInterfaceOrientation:duration:
-didRotateFromInterfaceOrientation:

, , viewController !

This interests me - "In my opinion, the controller (not the root view controller) . " How to add a view controller to a window hierarchy? Do you represent it or just add its representation as a subtask, say, a root view controller?

0
source

All Articles