scrollView中有多余的空白 - 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
notedit
V2EX    iDev

scrollView中有多余的空白

  •  
  •   notedit
    notedit 2013-04-11 22:49:10 +08:00 4765 次点击
    这是一个创建于 4566 天前的主题,其中的信息可能已经有所发展或是发生改变。
    是这样的 我把一个带有navigationBar的view 放到 scrollView中上面大概会空出10 point 的距离 而放普通的view没有问题.

    有遇到的么?
    20 条回复    1970-01-01 08:00:00 +08:00
    aisk
        1
    aisk  
       2013-04-11 22:55:57 +08:00
    楼主现在做ios了?
    notedit
        2
    notedit  
    OP
       2013-04-11 23:10:04 +08:00
    @aisk 插 别打叉 做了一段时间了
    notedit
        3
    notedit  
    OP
       2013-04-11 23:14:13 +08:00
    设置 scrollView的contentInset 可以解决这个问题
    _scrollView.cOntentInset=UIEdgeInsetsMake(-20.0,0.0,0,0.0);

    但是其他的没有navigationBar的就会上移20px
    ewangke
        4
    ewangke  
       2013-04-12 01:44:37 +08:00
    @notedit 为啥要把带有navigationBar放到scrollview里?navigationController不是顶层容器么。
    好奇楼主的设计
    ashchan
        5
    ashchan  
       2013-04-12 13:13:20 +08:00
    @ewangke 也许会有这样的应用场景吧。比方说直接感觉 Letterpress 就是用了类似的层次结构。
    notedit
        6
    notedit  
    OP
       2013-04-12 14:58:22 +08:00
    @ashchan 是的 不知道有没有遇到的 很奇怪
    notedit
        7
    notedit  
    OP
       2013-04-12 15:00:04 +08:00
    @ewangke 恩 是有这样的设计需求 这样左右滑动就可以完成app的导航
    alexrezit
        8
    alexrezit  
       2013-04-12 15:23:15 +08:00 via iPad
    @notedit
    可以用 gesture recognizer 啊. 用 scroll view 很费内存吧.
    ashchan
        9
    ashchan  
       2013-04-12 15:59:28 +08:00
    @notedit 多出的空白可能是由于 UINavigationBar 与 UIStatusBar 的默认关系引起的,但如果是这个原因的话应该是 20px 。你上面 10pt 和 20px 都提到了,不确定实际是哪一个。
    ewangke
        10
    ewangke  
       2013-04-12 17:28:33 +08:00
    notedit
        11
    notedit  
    OP
       2013-04-12 22:18:12 +08:00
    @alexrezit 可以说的更具体点么
    notedit
        12
    notedit  
    OP
       2013-04-12 22:19:16 +08:00
    @ashchan 应该是UIStatusBar的问题 据说这个是个老问题了
    notedit
        13
    notedit  
    OP
       2013-04-12 22:20:22 +08:00
    @ewangke 他那个太复杂了 自己用scrollview实现了个简单的
    ewangke
        14
    ewangke  
       2013-04-12 22:41:16 +08:00
    @notedit
    @alexrezit 那个方法也可以考虑一下,简单的视图层次可以直接用superview相同的view,然后通过sendToBack/bringToFront和PanGestureRecognizer来实现(就是调整视图z顺序,然后对frame作动画)
    有点类似于ViewDeck,只不过是全屏动画
    https://github.com/Inferis/ViewDeck
    notedit
        15
    notedit  
    OP
       2013-04-13 00:07:16 +08:00
    @ewangke 恩 这个方法不错 但考虑到这两个view里面的东西都还比较复杂 这两个view是一级页面 还会有二级视图等 暂时先用scrollView来实现了
    alexrezit
        16
    alexrezit  
       2013-04-13 09:49:09 +08:00
    @notedit
    就是直接用 navigation controller 然后检测到左右滑动手势的时候 push/pop.
    qiang1012
        17
    qiang1012  
       2013-04-13 12:21:00 +08:00
    之前混用TabBar和NavigationBar来模仿微信的push效果时遇到过类似的问题,楼主可以参考一下这个代码片段:

    // tabBarController.view.frame = (0, 0, 320, 480)
    UITabBarController *tabBarCOntroller= [[UITabBarController alloc] init];

    // screenArea = (0, 20, 320, 460)
    CGRect screenArea = [[UIScreen mainScreen] applicationFrame];

    // frame = (0, 0, 320, 460)
    CGRect frame = CGRectMake(0, 0, screenArea.size.width, screenArea.size.height);

    tabBarController.view.frame = frame;
    tuoxie007
        18
    tuoxie007  
       2013-04-13 14:23:28 +08:00
    10pt,推测是statusbar的高度,so,是不是计算frame的时候和显示的时候,StatusBar的hidden不一致造成的?
    小心ViewController的生命周期,viewDidLoad/viewWillApear/viewDidApear几个函数别用错了
    wezzard
        19
    wezzard  
       2013-04-13 21:47:04 +08:00
    楼主的需求是要做一个苹果未提供的container view controller。建议楼主看看官方关于customize container view controller的文档和网上一篇关于abusing UIViewController的文章,刚开始的时候我在这里摔了很多。
    notedit
        20
    notedit  
    OP
       2013-04-13 22:57:44 +08:00
    @wezzard 看了那篇abusing UIViewController 之前想过自己定制一个container view controller 但后来发现稍微修改下scrollview就可以满足我的需求,而自己实现container view controller也可能出现这样或者那样的问题.

    事实上ios6.0里面pageViewController的一个选项可以满足我的需求, 但现在直接上ios6.0还稍微有点早.

    谢谢你的建议 如果遇到什么问题会考虑用container view controller来实现.
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2718 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 34ms UTC 07:45 PVG 15:45 LAX 00:45 JFK 03:45
    Do have faith in what you're doing.
    ubao 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