How can I bind a UIView's orientation to that of it's parent view? - uiview

I have a UIViewController, with a toolbar at the top. I have a few views that I'm going to be adding and removing, but I don't want them to cover up the toolbar. So I made another UIView, that fills the area beneath the UIToolbar, and am adding views thee, and it works great.
When I rotate the device though, the first subview rotates with the view controller, but the UIView inside of the UIView thats inside of the UIViewController doesn't rotate!
What can I do to make it rotate with the parent UIView?
PS- If you can think of a better way to do what I'm trying to do, I'm all ears!
EDIT:
To clarify, I have a UIView subview in IB, and that is all hooked up to the code just fine. Then, depending on the button selected, that UIViews subviews are removed, and then a new one is placed in the subview array. So I use addSubview to and removeFromSuperview to add/remove the view from the UIView that is a child of the UIViewController view...

Related

Why is my UIView drawing behind my other views?

I have a UIView which is opened and closed by a button onscreen. I am positioning it over a scrollable custom text area which is a bunch of UILabels added to a UIScrollView.
I've made sure that it is added last in my view hierarchy, in the xib. I have also tried calling bringSubviewToFront, and have even removed the UIView from the parent view and re-added it after doing the layout.
Nothing that I have tried prevents it from being drawn behind this UIScrollView. I have verified that my UIView is actually the last UIView in the hierarchy by looking at the view hierarchy in the debugger at runtime.
The UIView in question, shown as a smiley in the picture here, has children. It has a 3x3 grid of invisible UIButtons, and a UIImageView to draw the image, which is normally something other than the smiley. But I am operating on the parent UIView, not the children.
Is there anything I can try, to help diagnose this? To recap, I have done all the following:
the UIView is added last in my view hierarchy, after the UIScrollView. It is a child of the same parent (the root view) as the scroll view - hence, a sibling view of the scroll view.
after doing the layout, I've tried [self.view bringSubviewToFront:myView]
after doing the layout, I've tried doing [myView removeFromSuperView] followed by [self.view addSubview:myView].
The latter two operations are performed at the very end of my layout method.
Any ideas?

Adding a fixed-position view on top of a view

I have a UITableViewController inside a UINavigationController. I'm adding a "modal" subview to the tableView, which is a custom UIView when one of the rows is selected.
(It’s modal in spirit, not in the UIKit sense, since Apple doesn’t support modal views on iPhone, I’m adding it with a [self.view addSubview:customView] in my table view’s controller.)
I would like it to appear at the bottom of the screen and stay put there. I can get it to draw at the bottom, but once I scroll the table view, the view moves with it. Here are some illustrations:
Initial position (good):
Position after scrolling (bad):
I'm getting the bottom position by subtracting the height of all the chrome (navigation bar and status bar) as well as the height of the custom view from [UIScreen mainScreen].bounds.
How can I get the custom view to stay put? Should I constantly be adjusting its frame when the table view is being scrolled?
Your best and most flexible option is to switch to using a view controller with the table view as a subview so that you can change its frame and add sibling views. Then, when you want to add a modal you can run an animation to move the table view out of the way and slide the modal view in.
UITableViewController.view is an instance of UITableView. Means you added your custom view into a scroll view and that is why it scrolls. You can try to put your custom view into the tableFooterView property of the UITableView, which is the old school solution.
Personally I would create a container UIViewController and have UITableViewController be a sub viewController of it. Another sub viewController UIViewController or just a simple UIView could represent the footer.

Animating UIView with auto layout when the view is just created and about to appear

I have a UIView that contains subviews that contains subviews...(Hierarchy of UIViews).
Every UIView is set with auto layout. When I press a button, this UIView is created and then I would like it to drop from the top of the screen.
The problem when I use layoutIfNeeded in an animation is that if will animate everything at the same time as it is a newly created UIView (not yet display).
My question is, is there a way to do the animation of only the UIView dropping with all the subviews already laid out in it?
I guess you can do it by creating the UIView when UIViewController displays and then hide it but I was wondering it there was another way.
Cheers
If you call layoutIfNeeded right after you add it to a view, while still outside the view, it should lay out it's views correctly. And then in the animation you call it again so the view animate to the final position.

UITextField inside a UIView thats animated on touch dismisses the view and shows the keyboard

I have a structure for my UIView object and have form elements within it. I run the application and the program is in such a way that when i click a button inside the UIView, it moves the current frame upwards. But thats not the problem.
My phonenumberfield is of type UITextField which is inside a UIView and that UIView is a part of the parent View. I have one button called submit and a segment control on the Parent UIView. But when i touch the phonenumberfield or any textfield type on the parent view, the parent view gets dismissed and keyboard shows up. Its weird I cant understand what the problem is because can't debug this. :(
I had a problem with the constraints for Auto Layout I had set for my scrollview and managed to fix the constraint and my view started scroll. To animate the view, I set a constant height from the top of the parent view and animated the view by changing the constant which did not affect the keyboard anymore.

Add UIScrollView to UIViewController

I am trying to add a UIScrollView to an existing UIViewController (with navigation and tab bar) using storyboard and autolayout but I don't get this to work. Up to now I have added all components to the controller by dragging them on it. Now I try to group them in a UIView, so that I can make this UIView a subview of UIScrollView. When I drag my existing components as a subview of my newly created UIView the position of it is wrong. So I must manually correct all positions. Afterwards the compoents are 64px below their old position.
I just cant get it to work. Is there a tutorial or something how to add an UIScrollView to an existing storyboard?
This is the easiest way to learn how to control a UIScrollViewer within a Storyboard.
http://agilewarrior.wordpress.com/2012/05/18/uiscrollview-examples/
You might want to deselect Ajust Scroll View Insets in interface builder.
You can also set in your viewDidLoad :
self.automaticallyAdjustsScrollViewInsets = NO;

Resources