V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
xuhel
V2EX  ›  iDev

iPhone 的 CSS

  •  
  •   xuhel · 2011-03-16 13:42:02 +08:00 · 5571 次点击
    这是一个创建于 4791 天前的主题,其中的信息可能已经有所发展或是发生改变。
    貌似都不支持 横向和纵向分别定义。。。
    5 条回复    1970-01-01 08:00:00 +08:00
    fireyy
        1
    fireyy  
       2011-03-16 16:52:24 +08:00
    leojoy710
        2
    leojoy710  
       2011-03-16 16:55:00 +08:00
    @fireyy 正解...
    问题是切换的时候屏幕会闪...这个很烦...
    shinyzhu
        3
    shinyzhu  
       2011-03-17 08:43:03 +08:00
    我做过一个运行在iPad上面的Web App,但基本原理都一样的。
    在头部引用CSS文件的时候就可以为不同方向分别引入不同的样式表:

    <link rel="stylesheet" type="text/css" href="/content/css/mc.portrait.css" media="all and (orientation:portrait)" />
    <link rel="stylesheet" type="text/css" href="/content/css/mc.landscape.css" media="all and (orientation:landscape)" />

    响应方向变化可以为body注册orientationchange事件:

    <body onorientationchange="mcHandleOrientationChange();">


    js函数:


    /* OrientationChanged */
    function mcHandleOrientationChange(e) {
    switch (window.orientation) {
    case 0: //Portrait
    case 180: //Portrait (upside-down portrait)
    mcCommon.updateViewForOrientation('portrait');

    break;
    case -90: //Landscape (right, screen turned clockwise)
    case 90: //Landscape (left, screen turned counterclockwise)
    mcCommon.updateViewForOrientation('landscape');

    break;
    }
    }

    这样就可以了。但是以下是要注意的:

    当然你可以在脚本里注册body的事件,但是绝对不能用jQuery的代码注册orientationchange事件,否则转换方向的时候会非常非常卡。
    xuhel
        4
    xuhel  
    OP
       2011-06-13 15:53:13 +08:00
    不过经过实验把 @media screen 的判断都写在 一个 css 文件里面,只会读取到最后 @media screen 里面定义的效果。
    xuhel
        5
    xuhel  
    OP
       2011-06-13 15:54:11 +08:00
    还是谢谢大家,这个用@shinyzhu 的方法解决了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2544 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:56 · PVG 23:56 · LAX 08:56 · JFK 11:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.