【问题标题】:Hide a part of the screen when scrolling down向下滚动时隐藏屏幕的一部分
【发布时间】:2013-12-10 09:13:43
【问题描述】:

视图的顶部显示一个带有所选联系人信息(照片、姓名、地址等)的矩形。在这个矩形下方,有一个 UITableView 显示其操作(一个单元格,一个操作):

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

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

编辑(精度):

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

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

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

【问题讨论】:

  • 在 xib 矩形剪辑子视图中检查?
  • 将联系信息添加为自定义单元格(使用不同的部分?)可能是一个想法。这样,您可以保持相同的滚动视图 (UITableView)。
  • 这可能是一个想法,是的,但它没有针对我的应用进行优化,因为我需要在 UITableView 上方显示一个 searchBar。

标签: ios iphone uitableview autolayout


【解决方案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);
    }

}

如果从上到下,从下到上滚动,这将重复。如果我犯了任何错误,我认为它会起作用。有人随时纠正我。

【讨论】:

  • 不清楚,所以您只想将表格视图设为全尺寸?但不想为表格单元格添加操作是这样的吗
  • 感谢您的关注。是的,我只想在向下滚动时使 tableView 全尺寸,并在向上滚动到其开头时将其缩小到原始大小。我试过你的代码,它只适用于第一部分。我解释说:当我向下滚动时,联系信息视图会离开屏幕。伟大的。但是当我向上滚动到 tableView 的开头时,我想再次查看联系信息视图...在您的代码中,tableGener 是什么?对我来说,它是一个包含联系信息和 tableView 的滚动视图。
  • tableGener 是我没有使用滚动视图的表格视图,我说我只是给出了一个想法@Erzékiel 尝试像这个地方contactview 在顶部之后那个地方Tableview 对我来说它适用于向上滚动和向下滚动
  • 你说得对,当我修改一行时它就起作用了。请看我的回答。非常感谢你的帮助 Yohan。
【解决方案2】:

在您的 .xib 中放置 ScrollView。和 IBOutlet 它是“scrView”。 将第二个视图和 IBOutlet 放在该 .xib 中的“tmpView”中,并根据需要设计该视图,然后将简单的代码放入 viewDidLoad。

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

}

我希望这对你有用..

【讨论】:

    【解决方案3】:
        //-(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.
    

    【讨论】:

      【解决方案4】:

      这是我的工作解决方案!感谢 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);
      }
      

      【讨论】:

        猜你喜欢
        • 2011-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-17
        相关资源
        最近更新 更多