UIView in iPhone rotation - iphone

My app looks like this:
UIViewController -> UIScrollView -> UIView
Everything works well when user is rotating device.
However, if user rotates device to vertical and then other view is added AFTER user rotated device, new view is still in Portrait mode!
Any ideas what is wrong?

When addin the view, you have to manually adjust it's frame. Autoresizing only works when the view is part of a view hierarchy.

Related

UIView rotation doesn't work properly in Swift

My UIViewshould always be in fullscreen but that doesn't really work sometimes. Every time the user rotates the device, the method viewWillLayoutSubviews gets called.
Here I print the height and width of the UIView.
The height and width of the UIView are right (1024 width,768 height in landscape mode).
Anyway, on the iPad the View hasn't this size altough I write it to the Console.
In portrait mode everything works, but in landscape not so what could be the problem?
If the iPad is in landscape mode and I start the app it works but if I rotate it (then it's portrait) and rotate it back to landscape, the view isn't in fullscreen anymore.
Simply pin the edges of your UIView to the edges of the view controller's main view with constant of 0, once when you add the UIView to the interface, and all will be well thereafter.

Xcode storyboard view on rotation

I would like to have a view to the top or left of the device.
I have tried using a stack view to rotate the view but I was unable to use all interface orientations.
Example: the iPad orientation has a regular width and height in both portrait and landscape orientation. Thus I believe I cannot rotate the stack view axis on this device.
What are other options to keep the view how I want it preferably using the storyboard with auto-layout only but if needed using swift code.
Edit:
To clarify, both the blue and grey view can be seen as empty UIView for the purpose of this question.
To clarify, when you rotate the device, you want the text, buttons, etc to rotate but the background to stay the same (as in the view takes up the same screen area, but things in the view are rotated), correct?
If so, use size classes to give your views different constraints for different views

UIScrollView landscape problems

I'm playing around with the page control sample code.
I changed the code to start the app in landscape, the app opened in the simulator but the app was still in portrait mode in a horizontal simulator.
I then put the following code into the PhoneContentController.m file and the MyViewController.m file and changed the MyView.xib view to landscape.
- (BOOL)shouldAutorotateToInterfaceOrientationUIIn terfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrienta tion);
}
Now what happens is the app starts in landscape mode with the first image displaying correctly. The problem now is the other images are showing on their sides and the scrollview is scrolling vertically instead of horizontally.
How can I get this to scroll horizontally in landscape mode with all the images also in landscape mode?
The ContentController and PhoneContentController classes are not subclasses of UIViewController. Therefore adding shouldAutorotateToInterfaceOrientation to these classes has no effect.
The rotation event is sent only to the first UIViewController that is added to the window (actually its view is added). In your case, shouldAutorotateToInterfaceOrientation is only called for the first MyViewController which is a subclass of UIViewController. Therefore only the first image is rotated.
To make it work properly you need to find a way to change ContentController such that it extends UIViewController.

iPad Rotation and Keyboard pop up

I'm building an app that uses a UIView that contains a UIScrollView within it so that when the keyboard shows up, users can still scroll downwards to see the content within the view. It seems like I have gotten everything perfectly set up but when I rotate, everything goes completely unusable. The views are all out of place and I am unsure what's the strategy to handle this. I have the views autoresizing but they don't seem to be doing it correctly.
Should I manually check to see if the rotations have occurred and reset the frame without autoresizing or is there a way that I can accomplish this with auto resizing?
The situation is this:
Portrait mode - form fits fine. When keyboard shows up, scroll view is resized but form does not.
Landscape mode - form doesn't fit fine and when keyboard shows up, scroll view is messed up.
Do I need to resize the form view when rotated to landscape mode?
Thanks!
You can reposition things back to original by using:
-(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//reposition code
}
I have an issue where I want the keyboard to resign upon the ipad rotating.
If the keyboard is open in portrait, and I rotate to landscape, the keyboard appears in landscape.
HOW DO I RESIGN the keyboard when I rotate!
TY

iPhone - Prohobit UIView from rotating when the device is turned

I haven't been able to figure this out. Could someone please help me? I am trying to stop one UIView in my app from rotating when the device is turned.
I am working on a drawing app. Right now, when the device is turned, all UI elements turn with it. What I am trying to do is have all the buttons, menus, etc. turn, but have my canvas UIView be static and ignore the rotation of the phone.
If the canvas view is a subview of a view that rotates, then it will rotate as well. It's inescapable.
If you have one element of a view that you do not want to appear to rotate, you have use a rotation transform to programmatically rotate that one view back to the orientation and frame you want it have.
You could use the following to prevent the view itself from rotating:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return false;
}
Then manually rotate the individual elements you want rotated.
OP here. Rotating the view using CGAffineTransformMakeRotate() worked like a charm. Thanks, TechZen!