伙計們!
我正在嘗試在我的 tableViewCell 中制作影像影片。我的意圖是獲取 tableViewCell 中的 imageView,將其添加到視圖中完全相同的位置,然后使用縮放影片。目前,我的代碼如下所示,但是,我需要在每個時間段(滾動后)找到一個單元格中心點,我可以在同一個位置添加影像視圖。cellRect.origin.y 的值不斷增加,而我需要它恰好是我的 tableView 單元格的 center.y 點。你能告訴我我的錯誤在哪里嗎?
預先感謝您!
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! TableViewCell
cell.animateImageView = { [weak self]
guard let self = self else { return }
tableView.layoutSubviews()
var cellRect = self.view.convert(tableView.rectForRow(at: indexPath), to: self.tableView)
cellRect.origin.x = UIScreen.main.bounds.midX - (cell.photoImageView.frame.width / 2)
cellRect.origin.y = cellRect.origin.y (cell.photoImageView.frame.height / 2)
UIView.animate(withDuration: 3) {
} completion: { isFinished in
}
}
}
uj5u.com熱心網友回復:
如果我理解正確,這就是你的目標
- 您點擊具有 imageView 的 UITableViewCell
- 您想在與您點擊的單元格中的影像相同的位置創建一個新的影像視圖
- 然后從這個位置,你將用影片制作這個影像全屏
- 影片完成后你想做點什么
如果是的話,這是我的想法
我覺得這條線有第一個問題:
var cellRect
= self.view.convert(tableView.rectForRow(at: indexPath),
to: self.tableView)
讓我們看一下
藍色視圖完美地添加到我們想要的位置
在我們完成了棘手的部分之后,現在用影片完成剩下的部分非常簡單,這是完整的功能
func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath)
{
// Retrieved the actual cell that was tapped
let cell
= tableView.cellForRow(at: indexPath) as! TableViewCell
// Here I made a change based on my explanation above
let cellRect =
cell.photoImageView.convert(cell.photoImageView.bounds,
to: view)
let animateImageView = UIImageView(frame: cellRect)
animateImageView.image = cell.photoImageView.image
animateImageView.clipsToBounds = true
view.addSubview(animateImageView)
UIView.animate(withDuration: 2.0)
{ [weak self] in
if let strongSelf = self
{
animateImageView.frame = strongSelf.view.bounds
}
} completion: { (success) in
if success
{
// animation completed, do what you want
// like push your VC
}
}
}
我相信最終的結果就是你想要的

我希望這可以幫助你更接近你想要的結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427935.html
