As of now I have the following code:
float xCenter;
float yCenter;
if (self.splitViewController.interfaceOrientation == UIInterfaceOrientationPortrait || self.splitViewController.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
xCenter = 384;
yCenter = 512;
} else if (self.splitViewController.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.splitViewController.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
xCenter = 512;
yCenter = 384;
}
uinc.view.superview.center = CGPointMake(xCenter, yCenter);
Is there a better way to simplify this? All I want to do is to show this at the center of the screen. I tried assigning it to `self.splitViewController.view.center, but it does’t give me the center as I want.
uinc is a UINavigationController presented in UIModalPresentationSheet, but I want to change the size of it and therefore have to set the location.
You could start by using the
UIInterfaceOrientationIs*methods.Here is one way you could rewrite that snippet:
Instead of hard-coding center points you could retrieve the center of the screen via the
boundsorapplicationFramemethods of[UIWindow mainWindow](which do not take orientation into account).Another solution would be to use the center of your UISplitViewController’s view:
If you are attempting to create a loading indicator or some other element that should appear on top of everything else on the screen, you should consider adding it directly to your app’s UIWindow. In this case you will need to detect the interface orientation and rotate your view accordingly.
I suggest looking at the source of MBProgressHUD which uses this approach (as a configurable option).