点击时展开 UICollectionView 及其单元格

2024-04-15

我正在尝试制作一个过渡动画,如链接中的演示here https://dribbble.com/shots/2733571-Citadela-countries。因此,当我单击该单元格时,它会展开并覆盖整个屏幕。

这是我的代码(我不得不承认我对 CollectionView 不熟悉)`

import UIKit

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

@IBOutlet weak var mainDesLabel: UILabel!
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var secDesLabel: UILabel!
let searchBar = UISearchBar()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    self.collectionView.delegate   = self
    self.collectionView.dataSource = self
    self.collectionView.backgroundColor = UIColor.clearColor()
    ////////////////////////////////////////////////////////////////////////
    self.searchBar.frame = CGRect(x: 175, y: 0, width: 200, height: 50)
    self.searchBar.searchBarStyle = UISearchBarStyle.Minimal
    self.searchBar.backgroundColor = UIColor.whiteColor()
    self.view.addSubview(searchBar)
    ////////////////////////////////////////////////////////////////////////
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 10
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell

    cell.layer.cornerRadius = 5

    return cell
}



func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
}

//Use for size
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    self.collectionView.frame = self.view.bounds
    let cell = collectionView.cellForItemAtIndexPath(indexPath)
    cell!.frame = CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height)
}


}

所以我认为使用“didSelectItemAtIndexPath”会有所帮助,但事实证明this https://i.stack.imgur.com/MxR8F.png

想法?任何帮助将不胜感激!


或者您可以做的是展开项目并使用 UIAnimation 更改其框架。

当点击单元格时,您还可以使用自动布局来扩展单元格内的视图,我正在暗示(剪辑到边界)。

像这样的东西:

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    let item = collectionView.cellForItemAtIndexPath(indexPath) as! cellCollectionViewExpress  // or whatever you collection view cell class name is.

    UIView.animateWithDuration(1.0, animations: {
        self.view.bringSubviewToFront(collectionView)
        collectionView.bringSubviewToFront(item)
        item.frame.origin = self.view.frame.origin   /// this view origin will be at the top of the scroll content, you'll have to figure this out
        item.frame.size.width = self.view.frame.width
        item.frame.size.height = self.view.frame.height
    })
}

我建议您使用 UICollectionView Controller,因此使用它通常会很轻松。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

点击时展开 UICollectionView 及其单元格 的相关文章

随机推荐

  • Eclipse 上下文帮助

    现在我可以在 Eclipse WizardDialog Editor 中注册上下文帮助 1 我创建了一个help contexts xml 文件
  • 如何在animationDidStop委托中识别CAAnimation?

    我遇到了一个问题 我有一系列重叠的 CATransition CAAnimation 序列 所有这些序列我都需要在动画停止时执行自定义操作 但我只想要一个动画DidStop 的委托处理程序 但是 我遇到了一个问题 似乎没有一种方法可以唯一地
  • 在 C# 中以编程方式创建 DHCP 预留

    我被分配的任务是创建一个应用程序 该应用程序接收 MAC 地址并为该 MAC 地址创建 DHCP 保留 NET 中是否有内置的 API 可以轻松完成此任务 当我为基础设施编写应用程序时 Windows 2000 资源工具包中有一个名为 Dh
  • Python,如何在每一行中打印字典键及其值?

    请参阅下图以供参考 gt gt gt for key in d for item in d key print key item 1 2 1 3 2 4 2 5
  • 匿名命名空间:它们真的那么好吗?

    我一直在使用static关键字时间较长 用于定义内部链接 后来 我改用 C 风格 将本地事物包装在匿名命名空间中 然而 现在当我使用匿名命名空间多年后 我开始认为static关键字更容易使用 一个常见的问题是我有这样的模式 namespac
  • 不再支持 Xlsx 文件。设置新的 BW2 项目的解决方案?

    经过几个月的休息后 我本周恢复了 BW2 的计算 由于 XLRD 的更改 我的旧笔记本不再工作 它不再读取 xlsx 如果我理解的话 这个帖子 https exerror com xlrd biffh xlrderror excel xls
  • 为什么在打开连接的情况下会出现“阅读器关闭时调用 HasRows 的尝试无效”?

    我有这个代码 this is managed elsewhere SqlConnection connection connection Open this is one block of code separate from the ab
  • 如何将值参数传递给 Bootstrap 中的 modal.show() 函数

    我有一个页面显示当地咖啡馆的列表 当用户单击某个咖啡馆时 会显示一个模式对话框 其中已预先填写了 咖啡馆名称 该页面包含许多咖啡馆名称 表单应包含他点击的 咖啡馆名称 以下是生成为带有链接按钮的文本的咖啡馆名称列表 table class
  • SQL查询查找同一天安装和卸载应用程序的用户

    我正在尝试使用 Google BigQuery 中 Firebase Analytics 的数据来查找在同一天安装和卸载该应用程序的用户 这就是我到目前为止所得到的 我有一个查询 为我提供安装或卸载应用程序的用户 或 app instanc
  • Flask-WTF - validate_on_submit() 永远不会执行

    我正在使用 Flask WTF 这是我的表格 from flask ext wtf import Form TextField class BookNewForm Form name TextField Name 这是控制器 book ro
  • 如何从另一个视图更新一个视图的 UI [SwiftUI 问题]

    总的来说 我是 Swift 和 iOS 开发的新手 我正在 SwiftUI 中构建一个应用程序 假设不同文件中有 2 个单独的视图 MainView Results 和 TabBar 忽略命名 这只是一个示例 这 2 个视图位于 2 个单独
  • 从绘图中删除线

    只是一个简单的问题 我正在尝试在 R 中绘制图表 并且我已经介绍了如何做到这一点 但是如何删除刚刚创建的线 例如 x lt c 1 2 4 5 6 7 7 8 10 y lt c 40 30 10 20 53 20 10 5 plot x
  • 触发器和数据触发器有什么区别?

    他们看起来是一样的 有显着差异吗 我想我错过了一些东西 一个常规的Trigger仅响应依赖属性 A DataTrigger可以由任何 NET 属性触发 通过设置其Binding财产 但是 它的 setter 仍然可以仅针对依赖属性
  • 如何在协议中声明通用协议属性要求

    挣扎了一段时间 如果你能阐明这一点 那将会非常有帮助 我有一个APIWorkerProtocol它有一个属性要求 所需的属性是一个协议 即DataParserProtocol protocol APIWorkerProtocol var a
  • scala 类型的上限和下限

    考虑以下层次结构 class C1 class C2 extends C1 class C3 extends C2 class C4 extends C3 我想写一个只接受类型的函数C2 and C3 为此我想到了以下几点 def f C
  • Bootstrap 的工具提示在悬停时将表格单元格向右移动一点

    我在我的项目中使用 Bootstrap 3 1 1 我的表格中的每个单元格都包含如下数据000 or 111 悬停时 我想将此数据显示为工具提示 到目前为止 这有效 但是 当我将鼠标悬停在 td 所有相邻单元格向右移动 这是我的 JSFid
  • 向 UITextView 添加轮廓/描边

    我想将轮廓或描边添加到可编辑的UITextView用户键入的文本 就像模因一样 http t qkme me 3oi5rs jpg http t qkme me 3oi5rs jpg 我必须使用UITextView因为我需要多线支持 我已经
  • 如何使用 ggplot2 在多面图中定义 y 轴中断?

    我必须绘制具有不同范围值的数据 我正在使用 ggplot2 的构面设计和选项facet grid variable scales free 但是 我想设置 y 轴上的中断值 以便对于所有变量 中断都是c 0 max variable 2 m
  • 如何将对象注入到 WCF 验证器类中

    跟进使用依赖注入世界碳基金服务 https stackoverflow com questions 881705 how to inject an object into a wcf service 有没有办法将 DI 用于 WCF验证者
  • 点击时展开 UICollectionView 及其单元格

    我正在尝试制作一个过渡动画 如链接中的演示here https dribbble com shots 2733571 Citadela countries 因此 当我单击该单元格时 它会展开并覆盖整个屏幕 这是我的代码 我不得不承认我对 C