in my iphone app i have returned yes in the following method ,its worked and screens are rotating but contents are not fitting to the screen when its in the landscape mode
following is the code which i used
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
following is my output
how can i fit the contents of the screen to the screen size when its rotated,,can any one help me, thanx in advance,,
You should reset the views frame when the device is about to be rotated. This should be usually done in willRotateToInterfaceOrientation method.
You can also simply use autoResizingMask which will automatically resize the view when its superView frame changes.
// Add this line in loadView method
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
read this tutorial:
http://www.shinstudio.com/blog/programming/rotating-view-in-iphone-app/
implementing willRotateToInterfaceOrientation will be solution
Related
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 :)
I'm using a standard UIPicker view as an inputView for a textField in an iPhone application. When the view is loaded in either landscape or portrait, the picker is sized the same as the appropriate keyboard. However, when you rotate the device once inside the view the picker doesn't resize it's height properly, like it does with it's width. I have UIViewAutoresizingFlexibleWidth set. When I tried setting UIViewAutoresizingFlexibleHeight as well the picker gets messed up (choppy graphics, component cuts off) on rotation, though the height is correct! Has anyone figured this out?
I found that if you are working with iOS 7 simply add:
pickerView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
This solved the problem for me. The transition isn't very choppy, looks like it "should" look.
I found a band-aid:
In didRotateFromInterfaceOrientation: in your hosting viewController, call setNeedsLayout on that picker view. The weird layout glitches are visible during the rotate but clean up at the end.
I have added one UIScrollView and 2 UIImageView into it. It shows up fine in potrait mode. But it hides it in landscape mode. I am running from xcode n simulator and implemented the method - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation.
I am new to iPad programming and lil stuck. Appreciate any help.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
[self.view insertSubview:scrollView aboveSubview:imageView];
}
else
{
[self.view insertSubview:imageView aboveSubview:scrollView];
}
return YES;
}
The problem seems to be the autoresizing of these views you've added. If you created them from Interface Builder go to the fifth tab on the right panel and select a view, there you can set the view to adjust it's size and position when the parent view changes it's size (which is what happens when you rotate the device). If you created these view from code you should set the autoresizing mask (use the method setAutoresizingMask:), you can add several values to obtain the desired effect.
hope this helps!
I'm having problems making my app iPad compatible.
I have an implementation of a custom Tab Bar, based on the post here http://www.wiredbob.com/blog/2009/4/20/iphone-tweetie-style-navigation-framework.html
That all works fine apart from when the device is rotated. The currently selected view rotates and resizes perfectly. Every other view rotates but does not resize to fill the space. There is a large white column down the right hand side.
I've tried adding
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;
to the tab controller view.
I've added similar code to the tab's views viewDidLoad methods.
I've tried to make the willRotateToInterfaceOrientation call all the subviews rotation methods but still no luck.
Any suggestions would be more than welcome at this stage. I'm hoping i'm not overlooking something obvious but i might be. I've been at it for a few hours now
Screenshot 1 -
Screenshot
Ok I Solved this problem.
What I had to do was manually call a resize on all the sub views. - i added a changeFrameSize function to each sub view (just so it made the code look a little nicer)
Oh and when adding views as sub views always use belowSubView method -
[self.view insertSubview:viewController.view belowSubview:tabBar];
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[(ViewControllerClass *)[viewControllers objectAtIndex:0] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:1] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:2] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
}
So because the selected view controller was always rotated and resized to the correct size, once it had rotated and adjusted i simply passed the same parameters to the sub views so they would resize too.
It's quite frustrating not to be able to do such a simple task: I have an "app" with a single viewcontroller, and in it a single UIImageView, that's initialized to a specific image at potrtait mode.
Now when the iPhone gets roteated to landscape mode and the shouldAutorotateToInterfaceOrientation event fires, at which I return YES, my resulting UIImageView looks totally screwed up: either the image is stretched so to fill landscape mode frame (which looks ridiculuous of course) or the top and bottom of the image are cropped.
How can I have my UIImageview and the contained image handle the device rotation gracefully, and display normal looking image at landscape mode as well?
Set the image view's parent UIView autoresizesSubviews to YES.
Also set the autoresizingMask of the image view to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
you also want to look into your UIImageView's contentMode. aspectFill and aspectFit behave very differently.
You can always subclass UIView and override the layoutSubviews method to manually lay out your subviews. The transition to landscape will still be animated, and you can do whatever you want with the subviews.