iPhone 的 CSS - V2EX
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 6143 次点击
    这是一个创建于 5397 天前的主题,其中的信息可能已经有所发展或是发生改变。
    貌似都不支持 横向和纵向分别定义。。。
    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     Solana     3071 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 11:25 PVG 19:25 LAX 03:25 JFK 06:25
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86