向下滚动时隐藏屏幕的一部分

时间:2013-12-10 09:13:43

标签: ios iphone uitableview autolayout

视图的顶部显示一个矩形,其中包含所选的联系人信息(照片,姓名,地址等)。在这个矩形下,有一个UITableView显示其动作(一个单元格,一个动作): enter image description here

当我向下滚动以查看“action 46”时,我想逐渐收缩接触矩形,最后完全隐藏它。 (操作比联系信息更重要,用户不希望总是在屏幕上看到它,更喜欢全屏查看操作)。 例如,在快速滚动之后,结果如下:

enter image description here

我不知道该怎么做......你能指导一下吗?

EDIT(精度):

我想在向下滚动时以全屏模式显示tableView,因为它表示用户无需始终在屏幕顶部看到联系人信息。单击单元格时没有任何行为。该应用程序只代表一个联系人(顶部)及其所有动作(底部,即tableView)。 无论如何,我的问题是我可以使用这个收缩顶部(联系信息):

container.frame = CGRectMake(container.frame.origin.x,
                             container.frame.origin.y,
                             container.frame.size.width,
                             container.frame.size.height - 2);

但是当我按-2替换+2时,它不起作用......

4 个答案:

答案 0 :(得分:1)

我编辑了我的答案看一看。根据之前的答案,首先设计UI。根据您的愿望,首先添加搜索栏和一个用于显示联系人详细信息的视图和一个显示操作列表的表视图。

最初在底部设置UiView,然后使用表视图设置。向表视图行添​​加操作 然后使用didscroll委托方法来识别是否开始滚动,当滚动开始时减小联系人视图的大小。然后当你向上滚动时,在联系人视图的高度上做+2,这不是完整的解决方案,我只是想出了一个可以实现你想要的想法。

当您希望tableview在滚动检查contentoffset

之后覆盖完整视图
     -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{


    NSLog(@"content offset:%f",self.tableGener.contentOffset.y);
    if(self.tableGener.contentOffset.y>100)
    {
    self.tableview.frame=CGRectMake(0, 0, 320, 568);
    self.contactview.frame = CGRectMake(self.contactview.frame.origin.x,
                                 self.contactview.frame.origin.y,
                                 self.contactview.frame.size.width,
                                 self.contactview.frame.size.height - 2);
    }

   else if(self.tableGener.contentOffset.y<100)
    {
        self.tableview.frame=CGRectMake(0, 0, 320, 568);
        self.contactview.frame = CGRectMake(self.contactview.frame.origin.x,
                                           self.contactview.frame.origin.y,
                                           self.contactview.frame.size.width,
                                           self.contactview.frame.size.height + 2);
    }

}

如果从上到下,从下到上滚动,这将重复。我认为如果我犯了任何错误,有人会随意纠正我的话会有效。

答案 1 :(得分:0)

在.xib中放置ScrollView。和IBOutlet它“scrView”。 把第二个视图和IBOutlet放在那个.xib中的“tmpView”中,然后根据需要设置该视图,然后将它放在viewDidLoad中。

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrView.delegate=self;
    [scrView addSubview:tmpView];
    scrView.contentSize = tmpView.frame.size;

}

我希望这对你有用..

答案 2 :(得分:0)

    //-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)i


    - (BOOL)textFieldShouldReturn:(UITextField *)textField
        {
            [textField resignFirstResponder];

            if (_gender == textField)
            {

                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.5];

                [self.view setFrame:CGRectMake(0, -40, 320, 480)];

                [UIView commitAnimations];

            } // here,if _gender textfield is selected the frame will set according to setframe co=ordinates.
            else if (_webpage ==textField)

            {

                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.5];

                [self.view setFrame:CGRectMake(0, -60, 320, 480)];

                [UIView commitAnimations];

            }

This is what I used to change the frame.This code shifts the view upwards when the stated textfield is selected, you need to pass the value of '**didselectrowatindex**' instead of textfield name..eg :- '_gender' etc.

答案 3 :(得分:0)

这是我的工作解决方案!感谢Yohan和其他人的贡献。

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if(self.myTBV.contentOffset.y>100)
        self.myTBV.frame=CGRectMake(0, 0, 320, 568);
    else if(self.myTBV.contentOffset.y<100)
        self.myTBV.frame=CGRectMake(0, 211, 320, 357);
}
相关问题