In my AppDelegate, I have an uiwindow like this. Inside that, there are uiimageview as background.
Problems is that those Imageview aren't rotated when iPad is rotated and status bar is also in landscape position already. May I know how to do?
Edited: If I listen to orientation change, my image view is rotated but I want to set that image view to the origin (0,0) of device. However, it look like uiwindow is offset in horizontal position. Now, I am setting origin of image view as origin of uiwindow. Then, my image view is also offset. How shall I do?
That's the correct behavior. UIWindow objects doesn't support rotations.
To do that, you should rotate them by yourself listening to UIDeviceOrientationDidChangeNotification notification.
Managing rotation in a window is a little bit tricky, also because during rotation animation you should be able to detect the rotation direction to make a good user experience.
In my opinion is better if you embed you image views in a view of a view controllers.
Related
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
I have a View Controller I have started an AVCaptureSession on the view of the View Controller,
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
Now I add it like this,
[self.view.layer addSubLayer: captureVideoPreviewLayer]
I also have added two buttons on storyboard in this View Controller, On rotation of the device the self.view should not rotate as it has the camera going on but I want the two buttons which are capture and cancel button to align and rotate,
How can I achieve this using storyboard.
Unfortunately this is not as easy as it should be. You may not simply "not rotate" a single view while the rest of the UI is rotated.
Since you are using a camera I suggest you to capture the the device orientation change through the notification center while keeping the controller orientation locked to whatever is your default or current state.
On orientation change you should then try and rotate the view with your buttons or anything else that should rotate. This is best done if all of the controls are added to a single view which has the same size as the view controller and is centered in the view controller. This means the constraints for this view are center x, center y, width, height. You need outlets for width and height and set them manually in the code. When view will layout subviews (it is a method to override in the view controller) simply set the width and height to the same as is the view controller controller.view.frame.size. Till this point your application should look exactly the same as it does now if rotations are disabled.
Now for the fun part: You need to check the current orientation and apply a rotation transform on the view with the buttons. What you need is a property holding the current interface orientation and upon changing that orientation you should apply a different transform to the view. The device orientation will not give you the interface orientation as device orientation includes extra positions. So when device orientation changes you need to use a switch statements and only on the 4 orientations that make sense should you change the interface orientation.
Once you have all that you should create a method that takes a user interface orientation as input and and will reposition the view with the buttons. (assuming you use portrait by default) You need to swap the width and height when the interface orientation is landscape as in widthConstraint.constant = controller.view.frame.size.height and apply a rotation transform depending on the orientation.
This method should be called when:
The controller will become visible with the application status bar orientation
When view will layout with the same orientation as was previously saved from view will become visible or device orientation change
When device orientation changes if the new orientation makes sense and is different then the currently set interface orientation
There are other ways of doing this though. For instance you may keep the rotation of the view controller and rotate the camera view with the same procedure and this is even easier since you may use viewWillTransitionToSize and animateAlongsideTransition but the animation will probably not be acceptable as you may see black parts when the view controller is oriented. Though I am not sure that will actually occur and even if it does it might be possible to fix it with disabling bound clipping on the controller view.
I noticed that when rotating the IOS camera APP its toolbars do not rotate.
The toolbars do not rotate but the content and buttons on the toolbar do rotate?
How can I achieve this effect?
It would be great if I could have some viewControllers on the same view
return shouldAutorotate = NO and some shouldAutorotate = YES
Right now I don't think doing a transformation on just the rotating views is a good option?
Is there any other way?
I am using IOS 6.
You'll need to override layoutSubviews in your UIView to position and rotate your buttons and images the way you want them. Check [UIApplication sharedApplication] statusBarOrientation in there to determine the current orientation, and rotate everything accordingly. Depending on how you've implemented your view controller, you might also need to override willRotateToInterfaceOrientation and/or didRotateFromInterfaceOrientation in your view controller to handle what happens before and after the rotation.
My application is always run in Landscape mode only. I have add four custom buttons on overlay view dynamically. I want to change the position of buttons when orientation change in landscape and portrait mode.How to position my Camera Overlay View buttons in a different location when my device orientation will changing?
Please help me to fix my problem. Thanks.
I have the same problem. It's not that we're not receiving the notifications. The problem is that the camera overlay view doesn't resize itself to fit the new orientation. For example, the view will rotate when going from landscape to portrait but the view still has a landscape aspect ratio, i.e., the view is wider than it is high.
Since i have a complex hierarchy of views i handle the rotation manually with CGAffineTransformMakeRotation.
Everything rotates in harmony, status bars, navigation bar etc. The only problem is, if the keyboard was on screen before rotation, it gets the orientation of the satiates bar but its size is not right.
How can i force it to fill the entire width and get the right height?
I tested with a single test UIview and it looks likes this.
http://dl.dropbox.com/u/15251533/iPhoneSimulatorScreenshot_20120430_133558.png
I found a simple approach to get rid of this situation.
If you call resignFirstResponder on the Textfield and afterwards becomefirstresdonder consequently.The keyboard appears in the right position after rotation.It also does not disturb the animation if you have one.