【发布时间】:2018-08-14 22:15:51
【问题描述】:
我想要实现的目标:我有一组图像,我想要水平滑动/滚动浏览。这些图像代表联系人。当我找到我想要的联系人(图像)时,我按下一个单独的开始呼叫按钮。此按钮连接到电话视图控制器。我需要在那个电话视图控制器上显示我正在呼叫的人的图像。为此,我需要知道我在启动 segue 之前使用的联系人图片。
My contacts view controller. Currently showing my scrollview attempt
我目前拥有的:我已经设置了一个滚动视图和一个单独的集合视图(它们无法相互连接。我有两个因为我想弄清楚哪个得到我需要什么)。两者都功能齐全,允许我翻阅阵列中的图像。 当我按下将启动 segue 到下一个视图控制器的按钮时,我无法弄清楚如何务实地获取正在显示的图像。
我最初试图标记图像,然后检索标记并通过 segue 将其传递给下一个视图控制器。 然后我尝试获取“当前可见”的图像的索引并通过 segue 传递它。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCollectionViewCell", for: indexPath) as! ImageCollectionViewCell
cell.imgImage.image = imageArray[indexPath.row]
//Get character for segue
selectedCharacter = indexPath.row
return cell
}
我还尝试获取图像名称并通过 segue 传递。
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCollectionViewCell", for: indexPath) as! ImageCollectionViewCell
switch cell.imgImage.image{
case UIImage(named: "Van"):
selectedCharacter = 2
case UIImage(named: "Fel"):
selectedCharacter = 3
default:
selectedCharacter = 1
}
}
我还没有找到任何通过滚动视图获取信息的方法。 Scrollview viewDidLoad 代码:
@IBOutlet var scrollView: UIScrollView!
for i in 0..<images.count {
let imageView = UIImageView()
let x = self.view.frame.size.width * CGFloat(i)
imageView.frame = CGRect(x: x, y: 0, width: 343, height: 244)
imageView.contentMode = .scaleAspectFit
imageView.image = images[i]
imageView.tag = i
scrollView.contentSize.width = scrollView.frame.size.width * CGFloat(i + 1)
scrollView.addSubview(imageView)
}
问题:是否有人对我如何获得我要呼叫的联系人以及我应该使用滚动视图还是集合视图有任何想法?
谢谢!
【问题讨论】:
-
显示一些代码。你试过什么?什么没有具体工作?您的问题过于宽泛,目前无法为任何人提供帮助。
-
@skladek 好的。做了一些修改。