iPhone 的屏幕分辨率是多少?

发布于 2024-09-09 04:01:41 字数 349 浏览 5 评论 0原文

我知道有人问过这个问题,但我仍然感到困惑。

我正在尝试为 iPhone 构建一个非常简单的页面:顶部的徽标、电话号码、地址和占据整个屏幕的 BG(不重复)。

当我运行打印屏幕宽度和屏幕高度的脚本时,我得到:320px * 480px。

然而,当我创建一个具有这些精确尺寸的 div 时,它很小。什么给?检测到的分辨率的整个尺寸的框是否应该占据整个屏幕?

那么,如果我正在为 iPhone 设计一个页面,并且希望它占据 Safari(在 iPhone 上)中的整个屏幕,那么我应该设计什么分辨率呢?

我使用运行 iOS 4.0 的 iPhone 3G 作为我的测试设备。

感谢您的任何帮助。

I know this has been asked but I'm still confounded.

I'm trying to build a dead-simple page for the iPhone: logo at the top, phone number, address, and a BG that takes up the entire screen (no-repeat).

When I ran a script that printed the screenwidth and screenheight I got: 320px * 480px.

However, when I created a div of those exact dimensions it's tiny. What gives? Should a box that's the entire size of the detected resolution not take up the entire screen?

So, if I'm designing a page for iPhone and I want it to take up the entire screen in Safari (on the iPhone) exactly what resolution should I be designing for?

I'm using an iPhone 3G running iOS 4.0 as my testing device.

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

时常饿 2024-09-16 04:01:41

您需要视口元标记来告诉 iPhone 您的网站是专门为其设计的。

使用这个:

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>

如果您需要用户缩放等,您可以更改缩放选项。

此外,如果您希望您的应用程序也以横向模式工作,您可以将宽度设置为 100%。

#wrapper {
    width: 100%
    max-width: 480px;
}

You need the viewport meta tag to tell the iPhone your website has been specifically designed for it.

Use this:

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>

You can change the scaling options if you need the user to zoom etc..

Also if you want your app to work in landscape mode as well, you can set the width to 100%.

#wrapper {
    width: 100%
    max-width: 480px;
}
梦开始←不甜 2024-09-16 04:01:41

问题在于 iPhone 正试图自行扩展。如果您将此标签放在页面的头部,它会告诉手机“别担心,我会自己处理内容的大小”,并强制屏幕比例为 1:1。

<meta name = "viewport" content="inital-scale=1.0">

The problem is that the iPhone is trying to scale it on its own. If you put this tag in the head of your page, it will tell the phone "Don't worry, I'll handle the sizing of the content on my own" and will force the screen to a 1:1 ratio.

<meta name = "viewport" content="inital-scale=1.0">
划一舟意中人 2024-09-16 04:01:41

其他答案是正确的,您需要配置视口。

有关此问题的官方苹果文档位于:

https ://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

值得浏览一下整个文档 - 以及大量视口标签的描述(附有图片!),它还有许多其他关于将网页定位到 iPhone 的有用建议。

The other answers are correct that you need to configure the viewport.

The official apple documentation on this is here:

https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

It's worth skimming through the whole document - as well as a lot of description of the viewport tag (complete with pictures!), it also has lots of other useful advice for targeting web pages to the iphone.

み零 2024-09-16 04:01:41

这取决于哪款 iPhone。最初的 3G 和 3GS 的分辨率为 320x480,4.0 是其两倍,为 640x960。如果你设计的是更高分辨率,旧款手机会将其缩小 50%,看起来应该不错。

您可能还想研究使用媒体查询来优化 iPhone 体验。 此博文

It depends on which iPhone. The original, 3G and 3GS are 320x480, the 4.0 is double that, at 640x960. If you design for the higher resolution, the older phones will scale it down 50% and it should look fine.

You might want to also look into using media queries to optimize the iPhone experience. There is more about that in this blog post.

无戏配角 2024-09-16 04:01:41

你可能想使用所有这些

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<!-- this one tells Mobile Safari to hide the Address Bar and make the app fullscreen -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

you probably want to use all of these

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<!-- this one tells Mobile Safari to hide the Address Bar and make the app fullscreen -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
殤城〤 2024-09-16 04:01:41

在 MonoTouch 中,尝试

 var yourFrame = FrameForOrientation(CurrentInterfaceOrientation);

使用这些方法

public static UIInterfaceOrientation CurrentInterfaceOrientation {
    get {
        return UIApplication.SharedApplication.StatusBarOrientation;
    }
}

public static RectangleF FrameForOrientation(UIInterfaceOrientation orientation, bool subtractStatusBarHeight = true) {
    var screen = UIScreen.MainScreen;
    var fullScreenRect = screen.Bounds;      // always implicitly in Portrait orientation.
    var appFrame = screen.ApplicationFrame;


    // Initially assume portrait orientation.
    var width = fullScreenRect.Width;
    var height = fullScreenRect.Height;

    // Correct for orientation.
    if (IsLandscapeOrientation(orientation)) {
        width = fullScreenRect.Height;
        height = fullScreenRect.Width;
    }

    var startHeight = 0.0f;
    if (subtractStatusBarHeight) {
        // Find status bar height by checking which dimension of the applicationFrame is narrower than screen bounds.
        // Little bit ugly looking, but it'll still work even if they change the status bar height in future.
        var statusBarHeight = Math.Max((fullScreenRect.Width - appFrame.Width), (fullScreenRect.Height- appFrame.Height));

        // Account for status bar, which always subtracts from the height (since it's always at the top of the screen).
        height -= statusBarHeight;
        startHeight = statusBarHeight;
    }
    return new RectangleF(0, startHeight, width, height);
}

public static bool IsLandscapeOrientation(UIInterfaceOrientation orientation) {
    return 
        orientation == UIInterfaceOrientation.LandscapeLeft ||
        orientation == UIInterfaceOrientation.LandscapeRight;
}

In MonoTouch, try

 var yourFrame = FrameForOrientation(CurrentInterfaceOrientation);

with these methods

public static UIInterfaceOrientation CurrentInterfaceOrientation {
    get {
        return UIApplication.SharedApplication.StatusBarOrientation;
    }
}

public static RectangleF FrameForOrientation(UIInterfaceOrientation orientation, bool subtractStatusBarHeight = true) {
    var screen = UIScreen.MainScreen;
    var fullScreenRect = screen.Bounds;      // always implicitly in Portrait orientation.
    var appFrame = screen.ApplicationFrame;


    // Initially assume portrait orientation.
    var width = fullScreenRect.Width;
    var height = fullScreenRect.Height;

    // Correct for orientation.
    if (IsLandscapeOrientation(orientation)) {
        width = fullScreenRect.Height;
        height = fullScreenRect.Width;
    }

    var startHeight = 0.0f;
    if (subtractStatusBarHeight) {
        // Find status bar height by checking which dimension of the applicationFrame is narrower than screen bounds.
        // Little bit ugly looking, but it'll still work even if they change the status bar height in future.
        var statusBarHeight = Math.Max((fullScreenRect.Width - appFrame.Width), (fullScreenRect.Height- appFrame.Height));

        // Account for status bar, which always subtracts from the height (since it's always at the top of the screen).
        height -= statusBarHeight;
        startHeight = statusBarHeight;
    }
    return new RectangleF(0, startHeight, width, height);
}

public static bool IsLandscapeOrientation(UIInterfaceOrientation orientation) {
    return 
        orientation == UIInterfaceOrientation.LandscapeLeft ||
        orientation == UIInterfaceOrientation.LandscapeRight;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文