How lower the uitextview current position in landscape mode? - ios

I have a scrollview which cointains a uitextfield, a uitextview and two label
The uitextfield and the two label don't scroll.
In portrait mode all works fine.
In landscape mode, I resize the scroll view in the way that the labels are not visible, only title and textview remains, but I have a problem when the user try to insert the text in the textview. The current position is under the title, so the user cannot see what he/she insert. I would lower it.
Using the autosizing masks in IB, don't change the situation: I have to make flexible only the uitextview.
What can I try?
I thought that scrollRangeToVisible could help me, but nothing.

Try using
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
or
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
in your view controller to place your uiTextView where you need it depending on the orientation. Change the textview's frame to something that works visually. I think the first method ignores IB's resizing masks, so you have to set coordinates for your objects' frames using CGRectMake. The second method will animate the rotation as per the resizing masks, but then will "all of a sudden" move the objects to where you specified their frames to be (again using CGRectMake).

Related

Autolayout causing UI Elements to "snap" into place at runtime?

I have a UIView with a UIImageView at the very top, a UILabel below it, a UIButton below that, and a UISegmentedControl that determines what determines what embedded UIview to display at the bottom (which also a choice to not show any at all).
I've run into the problem where I've set up all of my constraints in the interface builder, and everything seems to be fine when I switch between screen sizes in the storyboard. However when I actually run the project on a device or emulated, the UIimage at the top is briefly stretched before "snapping" into a size the fits the constraints. Also, it seems as if the label disappears for a brief second and reappears after the image has snapped into a size. After the "snap" has occurred, everything is in place and there are no problems.
This snapping occurs both when testing on a 4 and 3.5 inch display. I find this odd because I've designed the UI for the 4inch screen perfectly.
Does anyone know why this is happening?
Edit
Here's whats the constraints look like in IB.
This is potentially due to adjustments that you might be making to your UI elements (or constraints) from the view controller in code. For example, if you are programmatically setting a different UIImage into your UIImageView, and this code is happening too late in the view lifecycle (for example, in viewDidAppear) after a layout pass has already calculated view positions and sizes, then you will see a visible snap as views take on new positions based on the new intrinsic content size of the image view.
This could be caused by other adjustments such as injecting a localized string into a UILabel in code, which causes the label to have a smaller or larger intrinsic content size, which in turn affects the layout based on your constraints.
If you are making adjustments to your UI in code, make sure they are happening in viewDidLoad or viewWillAppear: so that they occur before the view's initial layout pass (and the view's animation onscreen).
If you're still seeing issues, you can try explicitly forcing an immediate layout pass to occur on the view controller's view at the end of viewWillAppear: by doing the following:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.view setNeedsLayout];
[self.view layoutIfNeeded]; // forces an immediate layout pass
}
Spacing between the UIElements might be the problem . Specially when using Pickers
Got it, You have applied constraint for Picker to adjust along with segmented control. So when app runs on 4 inch screen , picker automatically fits properly, but for 3.5 Inch picker always starts from bottom of the screen and picker will push segmented control upwards and hence segmented control will push rest control automatically.
Remove picker and segmented control constraint.

IOS Prevent text from stacking on screen rotation

I have a custom table view cell with two labels in it. If I rotate the screen the two labels stack on top of each other and behave badly. If I back out and display the view again while still in landscape mode they appear correctly.
I have figured out how to prevent this between a label and a textfield or a webview by pinning them with horizontal spacing, but that doesn't seem to be possible with two labels. Any suggestions would be much appreciated.
You may need to intercept the viewcontroller rotation delegate callbacks and handle them how you want by manually positioning labels on the screen.
I think all views should be re-positioned again in viewWillLaypitSubviews or viewDidLaypitSubviews methods. Otherwise, the resizing decision is put to iOS. If you don't want a resize, you can try playing with the autoResizingmask and autoResizeSubviews properties of the table view cell.

Changing height of a custom inputView when device rotates

I made a custom keyboard view and linked it to the inputView property of a UITextField.
Is there a way to change the height of a custom inputView when orientation changes and have the frame change animated smoothly just like the system keyboard?
My keyboard size is 768x272 and when the device goes landscape the size becomes 1024x272, but I want to make it bigger like 1024x372. If I change the frame with the code below when I get UIDeviceOrientationDidChangeNotification, the change animation is not smooth.
textField.inputView.frame = CGRectMake(0,0,1024,372);
Per Apple documentation for UIResponder.inputView:
"If UIKit encounters an input view with a UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard."
So if you want customized height, you shouldn't specify UIVieAutoresizingFlexibleHeight mask.
After many experiments, I found the best answer to my own question. A short answer is change frame when you get UIKeyboardDidHideNotification.
Custom inputView is embedded in another view controlled by the system called UIPeripheralHostView.
So changing the custom inputView at wrong time is not reflected immediately or shows an ugly layout at best.
When the device rotates, the system briefly hides the keyboard, then performs a rotation animation of the keyboard from old orientation to new orientation. I think the animation block is inserted somewhere between two notifications UIKeyboardDidHideNotification and UIKeyboardWillShowNotification. These notifications are coupled with UIKeyboardWillChangeFrameNotification. The "frame" in this notification actually means the frame of UIPeripheralHostView.
So changing the frame of my input view when I get UIKeyboardDidHideNotification gives the system a chance to adjust the frame of UIPeripheralHostView before the animation starts, resulting in smooth transition from short keyboard to tall keyboard during orientation change.
This works in iOS 5. But Apple may change the practice in the future.

UITableView portion loses interaction after device rotation

I have a UIViewController with a UIView subclass as a subview, and in here is a UITableView added as a subview of that UIView, as follows:
UIViewController
-UIView
--UITableView (plucked from a UITableViewController)
On an iPad, if I load the view controller in either orientation I can interact with the table view perfectly. However, if I rotate the device to a new orientation - I have code that alters the frames to make it fit the new resolution, but a small area of the table does not respond to touches and whatnot.
eg, we rotate portrait to landscape: if you imagine a portrait shape placed over a landscape screen - this area remains responsive, but a small strip to the right hand side does not respond.
Does anyone have any ideas what I may have missed? Thanks in advance.
EDIT: I have successfully verified the CGRect frames of all objects from the tableview cells through to the top UIViewController.
The area that looses its interaction must have fallen outside its superview's frame after rotation.
you can check that by setting tableView.clipSubviews = YES;
using this, will crop the tableview portion falling outside the superview.

Auto resizing UITableView on rotation with flexible width

I am adding UIButtons to a UIView located on the right side of a split view controller. Without any autoresizing set, the button text fully displays in landscape orientation. When I rotate to portrait orientation, all button text is fully displayed, but there is extra space on the right hand side of the UIView, because there is more real estate to work with.
I would like these buttons to resize on rotation so that it utilizes the entire width. I tried setting:
[button setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
With this in place, the same extra real estate exists on the portrait orientation, but in landscape orientation I get a lot of buttons with the text shortened with "..."
How can this be done?
when the AutoResisingMask doesnt do it for me, I always resort to subclassing the UIView and overriding the layoutSubviews... this way I can manually place those tricky views that never look right in different orientations.
in fact.. at last year's WWDC, I heard an Apple Engineer say that he "always" creates and adds his views with frame CGRectZero, then sets the correct frame in layoutSubviews. For what its worth...

Resources