I create UIView UIView in -viewDidLoad: and add them as subtasks to the view controller property:
- (void) viewDidLoad { [super viewDidLoad]; self.myView = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 280.0f, 210.0f)] autorelease];
Then I call -viewWillAppear: to center these subzones:
- (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self adjustViewsForOrientation:[[UIDevice currentDevice] orientation]]; }
I also override -willRotateToInterfaceOrientation:duration:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)newInterfaceOrientation duration:(NSTimeInterval)duration { [self adjustViewsForOrientation:newInterfaceOrientation]; }
The -adjustViewsForOrientation: method -adjustViewsForOrientation: sets the CGPoint center for various subview objects depending on the orientation of the device:
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { myView.center = CGPointMake(235.0f, 42.0f);
When the view controller is loaded, UIView instances are created and placed based on the current orientation of the device. If the device is subsequently rotated, the points of view are redirected to the new coordinates.
To make this smooth, you can probably use the key animation in -adjustViewsForOrientation: so that the subview moves more gracefully from one center to another. But at the moment it works for me.
Alex reynolds
source share