根据scrollview内容偏移量缩小和扩展uiview

时间:2013-12-20 06:44:54

标签: ios uiview

嗨,在我的应用程序中,我想实现像instagram navigationBar动画这样的动画..我做了所有的事情......我根据UITableview contentOffset收缩和扩展headerView ..它的子视图很好地收缩但是在扩展headerView时子视图高度 y 位置已更改..

 headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ? 64 : 44))];
        UIView *view1 = [[UIView alloc]initWithFrame:headerView.bounds];
        view1.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        view1.backgroundColor = [UIColor blackColor];
        view1.alpha = 0.1;
        [headerView addSubview:view1];

    headerView.autoresizesSubviews = YES;

// ..的UIImageView

    headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake((320 - 190) / 2 , (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ? 28 : 8), 190, 28)]; 
    headerImageView.image = [UIImage imageNamed:@"logo.png"]; 
    headerImageView.contentMode = UIViewContentModeScaleAspectFit;

    headerImageView.autoresizingMask =  UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [headerView addSubview:headerImageView];

//后退按钮

backButton = [UIButton buttonWithType: UIButtonTypeCustom];
        backButton.autoresizingMask =  UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [backButton setImage: [UIImage imageNamed: @"listLeftMenu.png"] forState: UIControlStateNormal];
        [backButton setFrame: CGRectMake(10, (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ? 34 : 14), 18, 16)]; 

        [backButton addTarget:self action:@selector(leftMenuAction) forControlEvents:UIControlEventTouchUpInside];

        [headerView addSubview:backButton];

        [self.view addSubview:headerView];

上面的代码是我的headerView初始化...

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{


    CGFloat height = (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ? 64 : 44) - scrollView.contentOffset.y;

    if (height < 0) {
        height = 0;
    }
    [headerView positionAtX:0  andY:0 withHeight:height]; // This is I change the x, y and height of the headerview..

    [postTable positionAtY:height];
}

我知道在展开时遗漏子视图框架的任何内容......请帮我修复此问题......

0 个答案:

没有答案