I have a view which is added in the form: [currentView addSubview: viewController.view];
If the view was added like [self presentModalViewController: viewController] then the view is displayed always ok, from landscape and portrait mode.
However, I can't use modal because the view needs to have transparent background and modal converts it to black.
The problem using the first method is that the nib is alway loaded in portrait mode, if the current orientation is portrait everything loads ok, and I can rotate to landscape without problem.
When my device is in landscape mode, the view is loaded as portrait again so it doesn't fit ok in screen.
I tried calling the rotation delegate methods: didRotateWithOrientation, willRotateWithOrientation, willAnimateRotation .. etc., however they don't rotate my view.
Is there any way to load the nib in a specific orientation or to rotate the view before it is added to my other view?
Unfortunately I don't think that this is possible, at least in iOS 4.
Check out this answer:
https://stackoverflow.com/a/4869207/472344
You might better off creating a custom view and adding that instead of a view controller.
Related
I have an application (iPhone only) that is portrait-only, but with one exception, a view that must be displayed in landscape mode.
I have implemented the technique described in the accepted answer in How to lock orientation of one view controller to portrait mode only in Swift, albeit in Objective-C.
Since I've overridden the -lockOrientation methods in -viewWillAppear and -viewWillDisappear of the landscape view controller, I don't undertand why I see rotation occur after the view appears; I would have thought that would occur before the view appears.
When my presented landscape view is overlaid by a presented portrait view, the portrait view starts out as landscape (because it's presented over a landscape view before rotation), but the rotated view has only the height it had in landscape mode.
When the portrait view is dismissed, the first, landscape view has now rotated to portrait mode, even though I've also implemented -supportedInterfaceOrientations and -preferredInterfaceOrientationForPresentation for landscape mode. This has been noted in UIViewController orientations, but there didn't appear to be any working solutions posted there.
Both view controllers, the landscape and the portrait that overlays it, are presented rather than pushed.
Also, the only flag set in the project's Info.plist is Portrait. The full-screen flag is not set.
In short, it's a hot mess just trying to make one exception to view orientation in my app.
Any clues to solving the behavior I've described would be greatly appreciated.
On iOS7, i have a viewController added as a subview to the root view controller like so:
[self.view insertSubview:self.tutorialViewController.view aboveSubview:self.accessoriesView];
What happens is in viewDidLoad and in viewDidAppear, it loads with landscape mode dimensions, instead of portrait.
This also happens on iOS6 and bellow, but somehow it gets resized so this is not an issue. It seems that self.view.frame is not always reliable: http://bynomial.com/blog/?p=85
What could be the cause of this and how can i fix it?
I developed an iPhone-only application and now I am making it universal. On iPhone it will run in portrait orientation, while on iPad I want to force it to run in landscape orientation.
I am facing a strange issue, since all the controllers I create for the iPad version seem to have a portrait orientation. I have a main controller, then I usually create more controllers and add their view to the main controller's view. This latter views are created with a frame that fits the portrait orientation and not the landscape one. All these controllers implement the -shouldAutorotateToInterfaceOrientation: and -preferredInterfaceOrientationForPresentation methods to force the landscape mode. Probably this is not sufficient.
Moreover, my biggest issue is with my latest attempt to create a flip-view animation:
[UIView transitionFromView:self.view
toView:about.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromBottom
completion:^(BOOL finished){
}];
When I call this method, the new view will appear onscreen but, obviously, it's rotated.
The orange bar should appear on the top of the view, and should occupy all the visible space. Seems like it's in landscape mode but added to the main view with the wrong rotation.
Could you give me hints to solve this?
Apparently to make things work correctly on an iPad you have to use a UINavigationController as the root view controller for the main window. Otherwise you will come to face problems such this one. In fact, setting a navigation controller as the root controller has completely fixed all my problems while handling rotations.
NEW EDIT:
I have narrowed my problem to this - i have a view that i add to my main view. That view is nib file in portrait orientation. That view can be added both in landscape or portrait mode. After adding it as subview how do i tell it, device is now in landscape mode, you should autoresize to fit?
OLD:
/*
I have a view, that is loaded via [NSBundle mainBundle] loadNibNamed. When button show is pressed view should show, and likewise when button hide is pressed view should hide. And this works ok.
Problem is with when device orientation is changed (lets say from portrait to landscape mode). If view is shown it resizes ok, and everything works fine. But if view is hidden, and i rotate the device and press show, view is shown, but not adjusted to new layout. It retains its original dimensions.
It is as automatic resizing is only applied to visible components. Is there some way to force resizing of the view?
*/
When you add your view, use the following:
[subViewFromNib setBounds:[viewYouAddedSubviewTo bounds]];
I have created a modal view in Portrait mode. when it is in lanscape mode it is not rotating.
How to rotate a modal view from Portrait to Lanscape in splitViewController?
I have a similar problem. The modal view is loaded from the DetailViewController, and when the iPad is rotated, the modal view disappears from view completely.
The closest I've come to a fix is, after rotating, to check whether a modal view was loaded, and then reload it, like so:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(self.modalViewController)
[self.modalViewController.view.window reloadInputViews];
}