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

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

  • 相关阅读:
    MySQL my.cnf详解
    函数:sleep-exit-wait
    fork-小实验
    OS-进程调度
    CET-4流程
    SDK和API的区别
    生活-金钱管理-不是理财
    算法设计与分析:Strassen矩阵乘法
    力扣:二进制加法求和
    算法设计与分析:大整数乘法
  • 原文地址:https://www.cnblogs.com/luqinbin/p/5090980.html
Copyright © 2011-2022 走看看