Autoresizing not working in portrait mode - iphone

I'm adding a view to view controller in which there are certain components. My project needs to support both orientation.
I designed the view controller using story board in landscape mode. When a button is pressed in the view controller the view is shown using the scaling animation.
It works perfect when its in landscape mode. When its in landscape mode and button is pressed it works perfect and also the rotation also works perfect. But if its in landscape mode and button is pressed the view doesn't get scaled according to the portrait mode and rotation is also a big problem.
I'm using autosizing and not auto layout
Can anyone please help me? Sorry for my bad english.
Any help is appreciated.

Autosizing has never proved to be the best solution for frame changes in orientation modes. Instead, change the frames manually in orientation delegate methods:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
check for your current orientation like:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
// change frames here for portrait mode
}
else
{
// change frames here for landscape mode
}
}

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 :)

UIView in landscape and portrait

I have a UIScrollView with some views in it, everything looks fine in portrait. However when I rotate to landscape all the views are jammed up. Basically what I want is to keep the views in place but then I would be able to scroll on it up and down. How do I deal with this?
Either you support just portrait orientation like this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
or you relayout your views by overriding this method
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
if you've designed your view in Interface Builder, you should pay attention to the Autosizing options in the Size Inspector!
Autosizing

UI ScrollView Hiding in iPad Landscape mode

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!

Orientation portrait and landscape mode

I have a 2 big logo images. In landscape mode all OK. When I change to portrait mode, the images lay one on the other. They too big for IB alignment
Can I set different views for each orientation?
or how can I fix this problem.
Update to saadnib's answer. Do not use shouldAutorotateToInterfaceOrientation. This method is for something else.
Your methods are:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
The former is called just before rotation occurs and the second one is called just after interface orientation.
You should replace UIViewController's view here or you can replace images for different orientations here too.
Use the following code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
for current orientation and according it change your image view frames.

iphone - programmatically rotate system keyboard to landscape when device is in portrait orientation

I would like to do this because the keyboard buttons are slightly bigger in landscape mode than portrait and I will have older users using my app.
Does anybody know a way to do it??
Thanks.
The keyboard will show up in the orientation of the statusbar, which doesn't always change with rotations for some reason. So if you want to display that view only in landscape set [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft; or whichever orientation you want to prefer in your viewWillAppear method.