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 年 4 月 11 日 · 4891 次点击
    这是一个创建于 4658 天前的主题,其中的信息可能已经有所发展或是发生改变。
    是这样的 我把一个带有navigationBar的view 放到 scrollView中上面大概会空出10 point 的距离 而放普通的view没有问题.

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

    但是其他的没有navigationBar的就会上移20px
    ewangke
        4
    ewangke  
       2013 年 4 月 12 日
    @notedit 为啥要把带有navigationBar放到scrollview里?navigationController不是顶层容器么。
    好奇楼主的设计
    ashchan
        5
    ashchan  
       2013 年 4 月 12 日
    @ewangke 也许会有这样的应用场景吧。比方说直接感觉 Letterpress 就是用了类似的层次结构。
    notedit
        6
    notedit  
    OP
       2013 年 4 月 12 日
    @ashchan 是的 不知道有没有遇到的 很奇怪
    notedit
        7
    notedit  
    OP
       2013 年 4 月 12 日
    @ewangke 恩 是有这样的设计需求 这样左右滑动就可以完成app的导航
    alexrezit
        8
    alexrezit  
       2013 年 4 月 12 日 via iPad
    @notedit
    可以用 gesture recognizer 啊. 用 scroll view 很费内存吧.
    ashchan
        9
    ashchan  
       2013 年 4 月 12 日
    @notedit 多出的空白可能是由于 UINavigationBar 与 UIStatusBar 的默认关系引起的,但如果是这个原因的话应该是 20px 。你上面 10pt 和 20px 都提到了,不确定实际是哪一个。
    ewangke
        10
    ewangke  
       2013 年 4 月 12 日
    notedit
        11
    notedit  
    OP
       2013 年 4 月 12 日
    @alexrezit 可以说的更具体点么
    notedit
        12
    notedit  
    OP
       2013 年 4 月 12 日
    @ashchan 应该是UIStatusBar的问题 据说这个是个老问题了
    notedit
        13
    notedit  
    OP
       2013 年 4 月 12 日
    @ewangke 他那个太复杂了 自己用scrollview实现了个简单的
    ewangke
        14
    ewangke  
       2013 年 4 月 12 日
    @notedit
    @alexrezit 那个方法也可以考虑一下,简单的视图层次可以直接用superview相同的view,然后通过sendToBack/bringToFront和PanGestureRecognizer来实现(就是调整视图z顺序,然后对frame作动画)
    有点类似于ViewDeck,只不过是全屏动画
    https://github.com/Inferis/ViewDeck
    notedit
        15
    notedit  
    OP
       2013 年 4 月 13 日
    @ewangke 恩 这个方法不错 但考虑到这两个view里面的东西都还比较复杂 这两个view是一级页面 还会有二级视图等 暂时先用scrollView来实现了
    alexrezit
        16
    alexrezit  
       2013 年 4 月 13 日
    @notedit
    就是直接用 navigation controller 然后检测到左右滑动手势的时候 push/pop.
    qiang1012
        17
    qiang1012  
       2013 年 4 月 13 日
    之前混用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 年 4 月 13 日
    10pt,推测是statusbar的高度,so,是不是计算frame的时候和显示的时候,StatusBar的hidden不一致造成的?
    小心ViewController的生命周期,viewDidLoad/viewWillApear/viewDidApear几个函数别用错了
    wezzard
        19
    wezzard  
       2013 年 4 月 13 日
    楼主的需求是要做一个苹果未提供的container view controller。建议楼主看看官方关于customize container view controller的文档和网上一篇关于abusing UIViewController的文章,刚开始的时候我在这里摔了很多。
    notedit
        20
    notedit  
    OP
       2013 年 4 月 13 日
    @wezzard 看了那篇abusing UIViewController 之前想过自己定制一个container view controller 但后来发现稍微修改下scrollview就可以满足我的需求,而自己实现container view controller也可能出现这样或者那样的问题.

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

    谢谢你的建议 如果遇到什么问题会考虑用container view controller来实现.
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   873 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 21:24 · PVG 05:24 · LAX 13:24 · JFK 16:24
    ♥ Do have faith in what you're doing.