I am using the following code in my willrotatetointerfaceorientation method.
if(UIDeviceOrientationIsLandscape(toInterfaceOrientation))
{
NSLog(@"willRotateToInterfaceOrientation landscape");
self.textFieldResult.frame = CGRectMake(146, 210, 97, 31);
self.operationLabel.frame = CGRectMake(73, 210, 120, 21);
}
else if (UIDeviceOrientationIsPortrait(toInterfaceOrientation))
{
NSLog(@"willRotateToInterfaceOrientation Portrait");
self.textFieldResult.frame = CGRectMake(305, 134, 97, 31);
self.operationLabel.frame = CGRectMake(82, 138, 120, 21);
}
This works fine if i rotate one time, i.e., lanscape to portrait or vice versa. But if i change from portrait to upside down, the orientation of the views get disturbed! the control is oing into the else block, but the orientation is not what it should have been.
What i am assuming is that for CGRect, the origin of the view is specified with respect to the top left corner of the parent view. which here is the window itself.
moreover, the coordinates which i specified here are totally different from what i see on the storyboard, i mean almost double or half! If i want to use the same code (as above) in my viewWillAppear method, then I have to use a different set of coordinates for the same placement of views, the coordinates similar to what i see on the storyboard.
I think I might not be clear about the working of CGRect and the corresponding functions.
You can use CGAffineTransform on that view to resolve that problem. For more info visit: THIS and THIS