UIScrollView landscape problems - iphone

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.

Related

UIWebview in a modal view is being shown in portrait in Landscape mode

I browsed through most of the questions and tried almost everything. But bad part is that the issue is still there.
I have a UIVIew which is always launched in landscape mode and I am presenting a second view (detailView) as a full screen modal view.
The detailview has a UIwebview on top of it.
When I present the detailView as a modal view, the webview is being shown in portrait mode.
I am returning "YES" in shouldAutoRotateToInterfaceOrientation and also have set autoresize , autoresizingMask and scalePageToFit properties.
When I rotate the device, and when the detailView is in front, the webview arranges to landscape properly.
The issue is only when I present the modalView for the first time.
Rotating the device is adjusting the layout properly.
As far as I am aware ModalViews on the iPhone do not support Landscape View. The case may be different for iPhone 5.
But it sounds like you are setting the ModalView not the WebView to landscape, I'd suggest a different approach to handling this.
For Example you could animate the DetailView in like a ModalView so it starts in the correct orientation
If you are running your app on iOS 6 you will need the following code in the modal view controller to support the landscape orientation:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL) shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
Also, make sure you are testing on the actual device as opposed to the simulator because auto-rotation behaves differently on the simulator.
That will do the trick:
CGAffineTransform transform = CGAffineTransformIdentity;
webView.transform = CGAffineTransformRotate(transform,-M_PI/2);
OK. First of all, the question I had posted was not clear. My question was that, when I load a webview, in portrait, it was loading the webview elements in landscape mode(CSS), and was getting loaded as portrait mode(CSS) in landscape orientation.
Turns out that I was not applying the correct CSS style.
The fix I did was:
In ViewDidLoad and willAnimateRotation method, I am posting a notification to my javascript to update the style based on orientation :)

Changing parameters on iOS device orientation

I have a Tabbar project in which one one the tabs should be on landscape mode. I've seen than the Tabbar controller only allows it only if all its views allow it. Son now I'm somehow forced to adapt all the views for both portrait and landscape mode, which I've never did before.
Am I right assuming that all should be done under:
-(void)willAnimateRotationToInterfaceOrientation...
so what happens with subview which are lazyly initialized? such as a footerView on a tableView?
Another thing is, I have a method to scroll the tableView so nothing is kept under the keyboard when it's called. The method uses a constant float + a variable. In landscape mode, the constant should be another.
Any feedback would be appreciated. Thanks in advance!
Read up on autoresizingmask - setting this attribute on your views will automate a lot of the orientation resizing.
And yes, you'll need a landscape and a portrait value for your constant.

Iphone View Rotation not functioning properly

I have a simple 1 screen app, with 1 View.. the view contains
a button, an textbox and a button across the top
A segmented controller across the bottom
and a MapView in between.
In portrait mode all is right with the world.. So I decided to begin to allow Orientation change...
in IB all views and elements and even the root window have autoResizeSubviews set
in My AppDelegate and my viewController I have also programatically added SetAutoResizeSubviews to yes explicitely I have set the autoResizingMask in the Root Window and the View Controller to FlexibleWidht | Flexibile Height
I have added the shouldAutorotateToInterfaceOrientation in my ViewController to always return true.
Yet, it doesn't work.. Or should I say it doesn't rotate properly.. in both portrait modes everything looks great, but both landscape modes, things don't get laid out or resized properly.. Basically all I see is the mapview, and its size gets slightly wider, but not much than the portrait mode, and it doesn't fill up the screen top to bottom.. all other interface elements with the exception of one button are invisible and it appears on TOP of the mapview.. as thought it just happened to be layed out over the view by coincidence than any design.
Anyone have any ideas what I am missing, or why?
Thanks in advance
You say "I have set the autoResizingMask in the Root Window and the View Controller" but that is a red herring. It is the buttons, the text box, the segmented controller, and the map view that have to have the correct autoresizingMask. If this view is being designed in the nib, you can set the values there and then turn the orientation right there in the nib and see what happens.
If you are unable to work out good autoresizingMask values for all those interface elements, implement didRotateFromInterfaceOrientation and perform the layout alterations in code when called upon to do so.

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

UIView in iPhone rotation

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.