zoukankan      html  css  js  c++  java
  • 导航控制器切换影响UIScrollView布局

    ios7 导航控制器切换影响UIScrollView布局的问题:


    如结果显示, scrollView 的子视图位置自动下移了。 而这个下移的距离刚好是 64.0px。


    解决方法:

    =====================

       第一种:在 ViewController 的 init 的方法中增加一行代码:


    Obj-c代码 收藏代码

    self.automaticallyAdjustsScrollViewInsets = NO;  


    =====================

    第二种: 让UIScrollView 不要成为 ViewController 的 View 的第一个子视图。具体操作:将 viewDidLoad方法 修改成如下:


    Obj-c代码 收藏代码

    - (void)viewDidLoad  

    {  

    [super viewDidLoad];  

    UIView *firstSubView = [[UIView alloc] initWithFrame:self.view.bounds];  

    [self.view addSubview:firstSubView];  

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(30.0, 64.0, 260.0, 300.0)];  

    [scrollView setBackgroundColor:[UIColor redColor]];  

    UIView *view = [[UIView alloc] initWithFrame:scrollView.bounds];  

    [view setBackgroundColor:[UIColor blueColor]];  

    [scrollView addSubview:view];  

    [self.view addSubview:scrollView];  

    }  



    =====================

    第三种:将 UIScorllView 的子视图上移 64.0px 。修改 viewDidLoad 方法:


    Obj-c代码 收藏代码

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(30.0, 64.0, 260.0, 300.0)];  

    [scrollView setBackgroundColor:[UIColor redColor]];  

    CGRect viewFrame = CGRectMake(0, -64.0, CGRectGetWidth(scrollView.frame),  CGRectGetHeight(scrollView.frame));  

    UIView *view = [[UIView alloc] initWithFrame: viewFrame];  

    [view setBackgroundColor:[UIColor blueColor]];  

    [scrollView addSubview:view];  

    [self.view addSubview:scrollView];  



    =====================

    第四种:设置导航栏的透明属性。

    self.navigationController.navigationBar.translucent = YES

    改变导航栏透明度,也会影响,这个可以根据自己的实际需求进行调整。

  • 相关阅读:
    利用Delegator模式保护javascript程序的核心与提高执行性能 (转)
    工作流
    蓝色垂直滑动效果的CSS导航
    JavaScript 多级联动浮动菜单 (第二版) (转)
    虚线效果水平CSS菜单
    红色玻璃效果水平CSS菜单
    CSS绿色水平多级下拉菜单
    ASP.NET中的Path(转)
    黑色与红色形成的水平CSS导航菜单
    紫罗兰水平CSS菜单
  • 原文地址:https://www.cnblogs.com/luqinbin/p/5090980.html
Copyright © 2011-2022 走看看