iPad in landscape gives wrong width and height - objective-c

I am making iOS 7 app where I am finding width and height in landscape mode.
What I have is below in app delegate...
NSLog(#"self.window.frame.size.width==%f", self.window.frame.size.width);
NSLog(#"self.window.frame.size.height==%f", self.window.frame.size.height);
What I was expecting is
self.window.frame.size.width==1024
self.window.frame.size.height==768
However I get reversed output as
self.window.frame.size.width==768
self.window.frame.size.height==1024
Note: I have ticked ONLY Landscape Left and Right. I have not selected Potrait & Upside Down.
Any idea why this is happening?
I am doing this on iOS 7.

The width and height of the screen and of the window in the screen don't change as the screen orientation changes, they will always be width = 768 and height = 1024 (until Apple makes an iPad with more pixels, like the height of iPhone's has changed).
In that screen window, you have a view controller with a root view. The size of that view will change with the screen orientation.

Related

How can I make a View's dimension stretch beyond the device dimensions?

I have a large image I would like to center in a View. I would like the height of the ImageView to take up 100% of device height, and whatever the width is to take up device width.
I don't want the images squashed to fit the width of the device, I want to see the center of the image and if any width is offscreen and invisible that's perfectly fine.
I've tried a few things but nothing works.
EDIT: My answer below works for iOS, but I still haven't figured out a way to get this to work properly on Android. I used ui.js by FokkeZB:
https://github.com/FokkeZB/UTiL/blob/master/app/lib/ui.js
This does what I want it to do with my image, but it's unfortunately a little slow (image loads after screen appears. I suppose I can load all images upfront and apply them later.
I ended up doing some simple math in this situation. Get height of the device:
var height = Math.floor(Titanium.Platform.displayCaps.platformHeight);
Then I set the height of my imageView to height of device. Next I needed the ratio of my image:
var ratio = imgOgWidth/imgOgHeight
And multiply that by device height:
var imageWidth = height * ratio;
And my xml was set up like this:
<View clipMode="Titanium.UI.iOS.CLIP_MODE_ENABLED" height="Ti.UI.FILL" width="Ti.UI.FILL">
<ImageView id="background_image" image="/images/myImage.jpg"/>
</View>
In my .js file I set my image width and height to the above. Works well! Probably different for landscape but this worked for my app which is locked to portrait.
Note: This is only working for iOS.

UIScrollview frame only updating correctly after scrolling

So I have created a UIScrollView as a subview of the view controller's view in Interface builder and set all auto layout constraints so that it resizes to fill its superview (Trailing, leading, bottom and top constrains set to zero with regards to its superview).
When I run the application, the scrollview does not initially update its frame to be the same size as its superview. the scrollview frame.size.width = 320 even though I am running it on iPhone 6 or iPhone 6 plus simulator.
As soon as I start scrolling, the scrollview frame gets updated to the correct value (same as its superview). why is this happening? shouldn't auto layout automatically resize the scrollview in relation to its superview?
The only way I managed to fix this is to add the following in viewDidLoad:
scrollView.frame = view.frame.
Any ideas why this is happening? It does not seem logical.
Many thanks
Ok, so after some experimentation, I figured it out.
I was checking the scrollview frame size in viewDidLoad and it was returning 320
However, it seems that auto layout will only do resizing AFTER viewDidLoad and will call viewDidLayoutSubviews() after it has finished resizing/repositioning...etc
Therefore, when I check the frame size inside viewDidLayoutSubviews, I get the right frame size 375 (for iPhone 6).
Thank you

Image size for the iPhone - Portrait vs Landscape

I have images of size 320 x 480. I left a blank space at the bottom of these images to account for the tab bar at the bottom of the iPhone screen.
The 320 x 480 looks good on the iphone in portrait mode but it looks stretched on landscape mode.
These images are loaded programmatically.
What can I do to not having them look stretched and perhaps how to use a higher resolution.
My understanding is that a higher resolution means the image will be too big for the iPhone screen.
Thank you.
I presume you are using UIImageView. By default the contentMode property of any imageView is set to UIViewContentModeScaleToFill that means it will fill the entire view thereby stretching the image.
change this to - [imgView setContentMode: UIViewContentModeScaleAspectFit], what this does is to respect the aspect ratio of the image.
more here in apple docs
The screen Size of iPhone and iPad are given below. Based on the mode you can create image size.
iPhone:
Portrait : 320x460
Landscape : 480x300
iPad:
portrait : 768x1004
Landscape : 1024x748

Navigation image too short in landscape

In my iPhone app, I've put an image sized 480 x 44 in the navigation bar, but when I change to landscape, the image becomes shorter. Please someone help me.
The image size is reduced because the navigation bar has a different size in landscape mode and it crops the portrait one (44px height).
Should be 32 pixels in height in landscape.
I would make 2 different versions of the image (landscape and portrait mode) and then implement -willAnimateRotationToInterfaceOrientation to select the appropriate version.

Navigation image width incorrect in landscape

In my iPhone app, my navigation bar image width does not change properly when transitioning to landscape. I'm using an image sized 480 X 34. Please, someone help me.
check your image size.....if less or more than make it 480*34