【问题标题】:SWIFT 3: List with Dropdown pictures/clipsSWIFT 3:带有下拉图片/剪辑的列表
【发布时间】:2017-01-25 12:07:01
【问题描述】:

我正在尝试开发一款外观与我附在此处的图片相似的应用,因为我真的很喜欢这个创意。

选择一个项目后,它会下拉并开始播放剪辑

关于如何实现这一点的任何想法?我可以使用表格和列表,但我不知道如何实际实现这样的东西。

【问题讨论】:

    标签: swift list dropdown


    【解决方案1】:

    您可以通过多种方式实现这一目标

    1. 让 indexPath = NSIndexPath(forRow: YourSelectedRow, inSection: 0)

        tableView.insertRowsAtIndexPaths(indexPath, withRowAnimation: .none )
      
           insert a different row here which will be tricky to manage.
      
    2. 创建所有这些标题,并在所选部分下仅创建一个单元格。

       var selectedSection =  -1 
      
        func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
         {
               let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 50)
               let button = UIButton(frame: view.frame)
               button.tag = section
               button.addTarget(self, action: #selector(selectExercise(_:), forControlEvents: UIControlEvents.TouchUpInside)
         }
      
        func numberOfSectionsInTableView(tableView: UITableView) -> Int
         {
              return 5 
         }
      
       func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
          {
              if section == selectedSection
               {
                  return 1
            }
           else
              {
                  return 0
           }
          }
      
            func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
           {
                      let cell = tableView.dequeueReusableCellWithIdentifier(“YourDetailCell”, forIndexPath: indexPath) as! YourDetailCell
              return cell
        }
      
       fun selectExercise(sender:UIButton)
          {
          selectedSection = sender.tag 
          }
      
    3. 创建两个单元格并使用动画更改具有整个单元格部分的特定单元格

      var selectedRow =  -1 
      
        func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
       {
              if selectedRow == -1
           {
                   selectedRow = indexPath.row 
                   tblConfirmedServices.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Bottom)
            }
              else
           {
                  selectedRow = - 1 
               tblConfirmedServices.reloadRowsAtIndexPaths([indexPathPre], withRowAnimation: .Top)
          }       
        }
      
       func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
         {
          if selectedRow = indexPath.row
           {
                      let cell = tableView.dequeueReusableCellWithIdentifier(“YourDetailCell”, forIndexPath: indexPath) as! YourDetailCell
                  return cell
           }
           else
           {
                  let cell = tableView.dequeueReusableCellWithIdentifier(“YourCell”, forIndexPath: indexPath) as! YourCell
                  return cell
         }
      }
      

    【讨论】:

    • 就个人而言,根据应该的工作方式,我会说选项2是“最正确的”。
    • 非常感谢!我要试试这个!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 2017-06-28
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多