UIView rotation doesn't work properly in Swift - 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.

Related

self.view.bounds in iOS 8 after rotation to portrait mode

In my app, I am dynamically using self.view.bounds to position subviews and I am not using Autolayout. When the view is rotated to portrait mode on iOS 8, I see self.view.bounds to be {568, 320} after view appears as opposed to natural behavior of {320,568} on iOS 7. How do I get this right ?
EDIT : I forgot to mention where I am doing this. This happens in viewDidAppear:. The value of self.view.bounds is incidentally correct in viewWillAppear but somehow it gets screwed up in viewDidAppear:.
EDIT 2: Here is I found on further drilling. Following is the scenario unique to my code :
a. Auto rotation is BLOCKED by me in code by returning only landscape orientation when the view is starting (this has to do with the camera & opengl setup I am doing and I do not want to autorotate the interface till everything is setup,
b.The view is freeform in XIB and has flexible width, height and all the edges in autoresizing mask.
c. Based on the above resize mask, iOS 7 gives self.view.bounds size equal to {320, 568} even though auto rotation has not happened. iOS 8 somehow ignores the same resize mask & the bounds is still {568,320}
So the root of the problem is UIWindow is autorotating in iOS 8 with the device while View controller is denying to autorotate.
In iOS 8, the rectangle returned by [[UIScreen mainScreen] bounds] takes into account the rotation of the device. No longer will the portrait frame be returned when the device is in landscape.
The updated-for-iOS-8 docs for UIScreen -bounds state:
This rectangle is specified in the current coordinate space, which takes into account any interface rotations in effect for the device. Therefore, the value of this property may change when the device rotates between portrait and landscape orientations.
Prior to iOS 8, the discussion section simply said:
Contains the bounding rectangle of the screen, measured in points. (read-only)

How to switch the live screen camera icons from portrait to landscape mode in iPhone?

I created a custom camera overlay for the live screen camera view and have imported my own custom icons for the camera, flash and flip buttons. Everything looks good in portrait mode, but when I switch the live camera screen to landscape mode, the orientation of the camera stays in portrait mode and shows this in console,
"Error: CGAffineTransformInvert: singular matrix"
I tried using the auto resizing mask, also have tried setting two different frames for the icons in both portrait and landscape mode in didRotateFromInterfaceOrientation method. But none of these are working.
My question is, will the landscape orientation support only the default iPhone camera overlay view or will it also support the custom overlayview.
Here are the screenshots indicating the behaviour of the icons repositioning each other when switched from portrait to landscape mode. I want exactly like this in my custom overlay view.
Edit:
I've made the live screen of my custom camera overlay to change by using the UIDevice Orientation method. But right now, the frame is not resizing when i try to switch from the portrait to landscape mode. So, i just want the entire frame to resize in landscape mode. Also, in this piece of code, if i try to change the value of CAMERA_TRANSFORM_Y,
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.234
self.picker.cameraViewTransform = CGAffineTransformScale(self.picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
the size of the overlay view reduces both from the top and bottom margin. But, more size gets reduced from the bottom than from the top margin. I want the overlay size to change uniformly both from the top and from the bottom margin.
This is my sample code,
Sample project

UIScrollView + UITextView resizing causes textView to scroll one line

I have a UITextView with isScrollEnabled set to FALSE. I then add it as a subview of UIScrollView. I then set the content size UIScrollView based on the size of the textView. You might wonder why I am doing this. But there is a need that it be done in this way alone. There is also a UIWebView that I add below the UITextView. I have to resize everything in textViewDidChange delegate method. Everything works fine as long as I don't rotate the view. When the device orientation changes to landscape. The first line of my UITextView scroll up and goes out of view. It never comes back on rotating over and over. My webView also behaves weirdly after rotation. It enlarges the font and messes it up. How can I avoid both these problems. Both UITextView and UIWebView are class variables that I create programmatically in viewDidLoad method of my viewController.
You should have 2 frames for each of these object and set them according to the rotation of the device.
In the device rotation delegate use an if:
- if landscape: set Landscape frames
- if portrait: set portrait frames
Hope this help

Forcing keyboard and sub-view orientation on iOS (iPad / iPhone)

We are just putting user input into our game so the user can enter email address etc. The entire game is Gl with no iOS UI at all. The EAGLView does not change orientation, it is always in portrait, however the game is in landscape and we handle this with a camera transform.
We want to bring up the iOS keyboard and overlay a UITextView for the text input. The UITextView is a subview of the EAGLView. Obviously it, and the keyboard, shows up in portrait as the EAGLView is in portrait.
Without having to change the EAGLView to landscape is there any way I can force the UITextView and the keyboard to show up in landscape orientation?
If I do change the orientation of the EAGLView to landscape to get this working, is there any hit on performance? I have read several times that orienting a GL view in anything other than the default portrait view will give a performance hit, although I can't find any solid evidence of this.
Thanks,
We think we have come up with a solution for this. We are doing two things, one for the keyboard and the other for the UITextView.
For the keyboard we are setting the status bar orientation. The keyboard follows when set.
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
And to get the UITextView to orient correctly we apply a transform to subviews of our EAGLView, which in this case is only the UITextView, as follows.
CGAffineTransform aTransform = CGAffineTransformMakeRotation(M_PI / 2);
[glView UpdateSubViewTransforms:aTransform];
This literally adds a 90 degree rotation to the view.
This has been tested on iPad & iPhone 4 with iOS 4.3, and on iPhone 3G with iOS 3.13.

trouble with rotating view (and resizing elements within) in ipad application

I'm having a nightmare with the rotation on iPad. I've searched all over the place for some tutorials, but nothing seems to really be for what I want. (Possibly not searching for the right thing?!)
I have a portrait view by default which is an image and a button inside the view. When I rotate, I detect this can work out if it's landscape. I then try to set the frame size of the uiview to fit nicely on the screen.
If I let it autoresize, it simply stretches and fills the screen. This I don't want.
but the trouble is, when I resize, the button gets resized too, but not in the same ratio as the image.
My question is: What's the best way to resize the view. I wanted to simply reduce the uiview by say 60% and it resizes EVERYTHING in that view with the same 60%. The only way I see this is working at the moment is to create two views... but that's twice the work and maintenance!
I've tried messing with the autosizing arrows in Interface builder, but that again seems to screw things up more!
I'm completely lost here!! Thanks for any info
The problem you have there is that the view is automatically resized to the screen ratio. On an iPad in Portrait Orientation the screen size is 1024x768. After the rotation to Landscape the origin rotates too and your screen content is skewed or stretched to 768x1024.
What you need to do is to override the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
message of the UIViewController of the view which rotates. This message is called within the animation block of the rotation. You just set the framesize of your subviews (the button) to whatever is best for you. Once i had a problem with rotating an OpenGL view. The content of the view was stretched when rotating to landscape. Since it is not possible to alter any OpenGL matrices within the animation block the only solution i found was to make the view quadratic and to set the origin behind the bounds of the screen (in -x direction). You have to override the message also to reset the origin above the screen (in -y direction) bounds in landscape mode, to keep the viewport in the middle of the screen. That way the view kept its ratio. Whatever solution is best for you, overriding this message should work out.
Have you tried disabling the autoresizesSubviews property on your UIView? It should prevent any size changes on the subviews when you resize your view.