Why my freeform ModalViewController always show full size? - ios

iOS7 and xCode5.
I created a UIViewController with XIB,
1, I unchecked the option "Use Autolayout";
2, Changed the Size to "Freeform";
3, Changed Status Bar to "None".
then I resized my view in xib (such like [280, 110]), but when I show the viewcontroller,
MyViewController *sellDialog = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
[self presentViewController:MyDialog animated:YES completion:^{
}];
the view always full screen size.

Choosing the "Freeform" option in the storyboard is only a "Simulated metric". When you present a view controller modally on iPhone, it will always appear full screen.
If you wanted to display your view controller over another view controller and have it not be full screen, you would need to come up with another solution. On iPhone, you would probably have to implement your own container view controller that shows the second view controller in a smaller frame. On iPad, you could show your view controller in a UIPopoverController.

Related

UIView in xib displays as portrait when opened in landscape

I just added a separate view controller and xib in a project that uses storyboards throughout. I display it from inside another view controller with the usual code:
OtherVC *othervc = [[OtherVC alloc] initWithNibName:nil bundle:nil];
[self.view addSubView: othervc.view];
In portrait orientation, he xib displays and auto rotates properly right out of the box.
But when I display it when the iPad is already in landscape, the size of the view is portrait and positioned off to the left.
What's going on? There doesn't seem to be a way to add constraints to the view.
Thanks!
This is not the right way to present a separate viewController.
The problem is that you are adding a view on the actual view..but this view have a certain frame that will remain the same when you add it on the view..in both case (landscape and protrait). So, to understand, you should check the orientation and then set the frame of the view properly. But as i said, the way that you are using is wrong.
In your case you should use segue from storyboard.
Or, at max, by code but with something like:
OtherVC *othervc = [self.storyboard instantiateViewControllerWithIdentifier:#"Identifier"];
[self presentViewController:othervc animated:YES completion:nil];
where Identifier is set in your viewController in the storyboard by the inspector panel at the right.
Or, if you instead wanted to say "NIB" you should to do:
OtherVC *othervc = [[OtherVC alloc] initWithNibName:#"yourNibName" bundle:[NSBundle mainBundle]]; //Or your correct bundle but i guess will be this.
[self presentViewController:othervc animated:YES completion:nil];
So after this, if you are sure to have set both orientation on your project, your view will be in landscape.
Now you will use AutoLayout or normal mask rules without AutoLayout to manage the elements on the view.

manage size of presented tableviewController

I have presented a tableview controller on a view controller.That tableview comes as full screen on view controller but I do not want to present the tableview on full screen.Is there any way to manage the size of presented vie controller. And the second problem is that i want to present a vie controller which have some label , some text boxes and a table view. Please help
IF you are using iphone device then the viewcontroller will occupy
the full screen .
If the device is iPad,then u can use modalPresentStyle.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourVC];
navController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:navController animated:YES completion:nil];
For iPhone ,add the views like UILabel,UITableview to the mainView and present it.
The UITableViewController is used when the table view is the main view of the controller.
In your case it seems more appropriate to use a normal (subclass of) UIViewController and add a UITableView as one of its sub views.
Then you can resize it as you prefer and add other elements (labels...) as additional subviews.
Usually in this configuration you may want to set the view controller as the delegate and dataSource of the table view.
Does this answer also your first question?
You could not change the size of the presented view controller. Another way to do it is by adding it as childViewController by:
[self.view addSubview:tableViewController.view];
[self addChildViewController:tableView];
Then you can change the size of the tableViewController as you wish.

Can't Resize UIViewController After Presenting Over UITabBarController

I've got a UIViewController that I would like to display over top of my UITabBarController kind of like a custom UIAlertView. The problem is that, when I present the UIViewController, I'm unable to resize its view to fit whatever screen is currently being used. The UIViewController (ShareViewController is its name) is designed using a .xib file, and it's currently using iPhone 5 screen height. I basically just want to resize its UIView (view) if the app is being run on any device, but it won't work when I call setFrame.
Here is some code:
ShareViewController * svc = [[ShareViewController alloc] initWithNibName:#"ShareViewController" bundle:nil];
self.tabBarController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self.tabBarController presentViewController:svc animated:NO completion:nil];
[svc.view setFrame:[[UIScreen mainScreen] applicationFrame]];
I use the "UIModalPresentationCurrentContext" setting so I can show the ShareViewController with a transparent background. So, when I run this code the ShareViewController just gets added but goes off screen because it is still at the iPhone 5 display height.
What can I do to resize my ShareViewController's main view?
Instead of presentviewcontroller better make it as addsubview and apply animation like present modal view controller
I gave the group of buttons a container which I then translated upwards depending on the screen center. This is a bit of a hack fix but I think there is a better way to implement this custom UIViewController anyway.

iOS: Apply view rotation to view controller under modal view

I have been following a solution on this question in order to display a view with a transparent background. The issue that I'm having is once the modal view controller has been displayed, the underlying view doesn't get rotated anymore.
For example if A is my view controller, then B is my modal view. The issue is as follows. I currently have my device in portrait and have A displayed. I then present B modally. I then rotate my device and B rotates with it, however A stays as it was.
Please could someone advise on how to handle this rotation so that the underlying view (A) gets rotated too?
ModalViewController is used to interrupt the current workflow and displaying a new set of views. So when you present modally, here in this case you are presenting B, the current active Viewcontroller is B and not A.
A ViewController is traditional controller objects in the Model-View-Controller (MVC) design pattern. They also take care of user interface, gesture recognitions,event management(of buttons for example) and the alignment of views in present in them.
When you presented B, the current viewcontroller changed from A to B and hence when you try to rotate(if the orientation support is provided) the view of B is effected as its the viewcontroller active and it responds to the rotation. Normally we go unnoticed these because the view is opaque. Here in your case the view is transparent and we notice that A has not responded to rotation.
I tried the above example in iOS6 (from the one you mentioned)
ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
here A remained in portrait mode
When i did this adding the second viewcontroller's view as a subview, A changed to landscape
ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.view addSubview:vc.view];
this happend because in the second trial the active viewcontroller was A and not B as B's view was a subview added to A. Go through Apples's Document on
About ViewController
About windows and views
Presenting ViewControllers

With UIPresentationFormSheet, why doesn't my view move above the keyboard when it is up?

Apple says:
UIModalPresentationFormSheet
The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
But my view doesn't move up when the keyboard is visible. I basically want to present a textview modally above the keyboard so the user can enter text and then hit send (in a nav bar button on the presented view.)
My presenting view is a UISplitViewController (not one of its children) and I'm presenting UINavigationController who's top view controller is basically a UITextView. Rotation works, but the presented view is overlapped by the keyboard in both orientations.
I found some questions asking how to resize the presented view in this case, which is nice, but I don't want to have to make assumptions by resizing manually in the presenter or in the presented view. It seems like it should just pick a decent (undocumented) size just move it up automatically when the keyboard shows.
My presenting code looks like this:
MyViewController *vc = [[MyViewController alloc] init];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self.splitViewController presentModalViewController:nav animated:YES];
As I was finishing up my question, I realized I was calling becomeFirstResponder on my UITextView in viewWillAppear. If you change it to viewDidAppear it will work, which makes sense.

Resources