UIView are not properly located in ViewController after Rotation - ios

I have a navigation controller with viewcontroller with container view, where views are loaded programmatically and based on the button click subview is loaded on top of the view. When I add subview from same orientation the views are laid properly but when the subview is rotated while adding on view, the subview is not properly located where they are supposed. How can I fix this issue?
Thanks

you can use auto layout or/and size classes or implement didRotateFromInterfaceOrientation to detect the orientation of device whether it is in landscape or portrait mode and then change the position of your UIView accordingly

You should use of autolayout or size class. Use orientation method than you can set subview possition according them.

Related

Disabling autorotation for specific UIView iOS 12

How do I allow one subview of my view controller to autorotate on an orientation change, but keep the others static. I'm trying to get an effect similar to the native camera app where the capture and switch cameras buttons (along with all the others) stay in their locations and just rotate accordingly. The SnapChat app also does this where the UI layer that pops up after you take a photo autorotates but the other views do not.
I seemed to be able to get close following the answers here: Disable autorotate on a single subview in iOS8, however, while this prevents them from rotating, it jumbles up their positions.
I think you have to use
(i) autolayout to set constraints on view by fixing its position or width height.
for setting orientation for portrait and landscape you have to use size classes
(ii) Another trick is you can use UIViewController to fix orientation using its mask orientation delegate. then add it add child of other UIViewController

My app's main view doesn't resize to fill the screen when the device is rotated

Recently I ran into an issue with my app when changing the device's orientation.
This is my main ViewController (let's call it VC1) in portrait mode:
Now if you push / present any viewcontroller (let's call that VC2), rotate the screen while in VC2, and return back to the previous view (VC1), this is what I get:
Why doesn't VC1 rotate correctly like it should? This issue happens throughout the whole app and with any two views. I honestly have no idea what might be causing this or where to look, so any help would be appreciated.
Do you use constraints and autolayout? Can you post a screeen where constraints of the view are visible? I think there are some missing constraints
your navigation bar is properly resize in portrait and landscape mode So The main problem is you didn't add trailing Constraints to your view.
Just Add you trailing constraints on your view in Storyboard.

Move subview to different view, in a different size class

I'm having a problem with moving subviews in different size classes, here is my problem.
I want to build two layouts for landscape and portrait (autolayout and size classes)
Here is the desired UI
In portrait I want the red view to be a subview of magenta view, while in landscape to move the red view to be the subview of the controllers view (the white view).
I can set different constraints for portrait and landscape for the red view, if it remains a subview to the magenta view and it all works fine.
But if I move it out to the white view, it disappears form the other orientation/size class.
Is there a way of solving this problem from Interface Builder, without duplicating the red view?
I'm trying to avoid to activate/deactivate constraints from code.
Link to the project.
Yes you can do that. From portrait size class set constraints. Then change size class for landscape and then drag this view out from it super view and put it to desired location.
And uninstall constraints of portrait class for this size class and set new required constraints for this size class.
Hope this will help :)

How to show UIButtons present on the view controller

I had a UIViewController on whose view I had started an AVCaptureSession and added two UIButtons to capture photos and close the camera,
I was facing the issue that the AVCaptureSession was also getting rotated when I was rotating the device,
To solve the problem I followed the second answer on this link,
<https://stackoverflow.com/questions/7353789/ios-disable-autorotation-for-a-subview>
But after adding on the window if I am making the view on the window of the full width and height as the self.view I am not being able to see the buttons
Any suggestions how I can bring the buttons visible while adding the window view as full width and height as the view of my view controller.
You will probably have to create a subView of the "full width and height" view that you have created, and put the buttons over there (instead of in self.view).
Edit:
You might also try calling bringSubViewToFront on both buttons.

UISplitViewController Common View

is it possible to have a common view for both master and detail view controllers.
What if I need to add a header image(at top, the very first view) common for both the master and detail view controllers. When the device is in the portrait mode the width of the header image view has to shrink to fit to the detail view controller's view and when the orientation changes to landscape the width of the same header image view has to be expanded that is the width of it has to be 1024. Please tell me whether doing this is possible. or any workaround for this?
I'm not sure about this, but you may need to explicitly set the image using a UIImageView in your DetailViewController and your RootViewController NIB. Then, during an Orientation change (Portrait -> Landscape), the UIImageView in the DetailViewController should automatically flip with the rest of the ViewController, giving you what you are looking for.
A splitViewController must be root view controller in your application. If you add splitViewController's view as a subview of some other viewController's view, splitViewController will not get the rotation events.
For your problem, change the design of your app so that the common view appears only in detailViewController part so that it will appear in portrait mode also.
If this is not feasible, the only option you are left with is to create your own splitViewController, so that you will be capable of adding it over some other views and send the rotation events to this splitViewController when rotation occurs.

Resources