Does max-width in media-queries uses the width or height? - media-queries

This question is a bit dumb but, for a long time I was confused about this. When we use max-width in the media query, does it apply to the current width, or does it apply to the longest possible width.
For example, we know that IPhone 4 is 320 x 480, if I want my query to apply only to the vertical view, then should I use max-width: 320 or should I use max-width: 480

That will depend upon whether the browser is in portrait mode or landscape mode. This can also be locked, based upon the answers to a previous question: How do I lock the orientation to portrait mode in a iPhone Web Application?

The width refers to the width of the current orientation.
In portrait view the width is smaller than the height. In landscape the height is smaller than the width.
When you goal is to have a layout for portrait mode then you should focus on that and not the width.
#media all and (orientation: portrait) { ... }

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.

iPad in landscape gives wrong width and height

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.

UIImageView within UIView doesn't respect constraint

I have a UIView of size width: 285 and height: 243. Within that view, I have a UIImageView (it is within that UIView according to Storyboard). That UIImageView has width 283 and height 241 (so that the UIView shows 1px around). I position that UIImageView 1px vertically and 1px horizontally from the UIView. Now, for some reason, everything shows fine within Storyboard, but once it runs, the UIImageView doesn't respect any of the height or width I gave. IF I set the mode to Scale to fill, it works, but I want Aspect fill which it doesn't work.
I am using auto-layout by the way. Any ideas?!
You haven't said what about it "works" so I'm going to guess.
Aspect fit, by its definition, will likely show a different border on 2 edges because it has resized the image for display. If your aim is to put a border around the image then you should:
Remove the container view (it offers no benefit)
Add a border to the image views layer
Calculate the aspect ratio of the image
Set the image view frame size to fit around the image
A number of options are described in this post: How to scale a UIImageView proportionally?.

UISplitViewController: How to derive detail view's width in pixels programmatically?

<detailView>.view.frame.size.width returns 768px, which is true for portrait but not landscape. How do I programmatically derive the width of detail view so I can layout its children views appropriately? I don't want to use hard-coded values
I've found out that <DetailViewController>.navigationController.view.frame.size.width works accurately for determining width in landscape mode.

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.