如何在滚动时一次旋转 table 视图单元格中的所有视图?
How to rotate all views in table view cells at once while scrolling?
我想一次旋转单元格中的所有 UIView,但我做不到,到目前为止,我可以在上下滚动时旋转位于顶部和底部的单元格中的 UIView,但中间table 视图单元格的 UIView 的一侧不旋转,它们仅在即将出队时旋转。
这是我的源代码:
//
// ViewController.swift
// scrollIT
//
// Created by AK on 10/2/19.
// Copyright © 2019 AK. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var indexPth: IndexPath!
@IBOutlet weak var tableViewz: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 23
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableViewz.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? RotationCell
indexPth = indexPath
return cell!
}
func rotationFunc(inIndexPath: IndexPath, someAngle: CGFloat) {
if let cell = self.tableViewz.cellForRow(at: inIndexPath) as? RotationCell {
DispatchQueue.main.async {
cell.rotatableView.transform = CGAffineTransform(rotationAngle: someAngle)
cell.rotatableView.layoutIfNeeded()
}
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let scrollOffset: CGPoint = scrollView.contentOffset
print(scrollOffset)
let degreesRotate: CGFloat = scrollOffset.y * (CGFloat.pi / 180)
rotationFunc(inIndexPath: indexPth , someAngle: degreesRotate)
}
}
我得到的输出是这样的:
https://media.giphy.com/media/WTuteL5oD3HmEk4kjR/giphy.gif
非常感谢您的宝贵时间和帮助!谢谢!如果我遗漏了什么,请告诉我!
试试这个,对所有单元格执行此操作:
for eachIndexPath in tableViewz.indexPathsForVisibleRows {
// do your rotation stuff here
}
我想一次旋转单元格中的所有 UIView,但我做不到,到目前为止,我可以在上下滚动时旋转位于顶部和底部的单元格中的 UIView,但中间table 视图单元格的 UIView 的一侧不旋转,它们仅在即将出队时旋转。
这是我的源代码:
//
// ViewController.swift
// scrollIT
//
// Created by AK on 10/2/19.
// Copyright © 2019 AK. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var indexPth: IndexPath!
@IBOutlet weak var tableViewz: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 23
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableViewz.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? RotationCell
indexPth = indexPath
return cell!
}
func rotationFunc(inIndexPath: IndexPath, someAngle: CGFloat) {
if let cell = self.tableViewz.cellForRow(at: inIndexPath) as? RotationCell {
DispatchQueue.main.async {
cell.rotatableView.transform = CGAffineTransform(rotationAngle: someAngle)
cell.rotatableView.layoutIfNeeded()
}
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let scrollOffset: CGPoint = scrollView.contentOffset
print(scrollOffset)
let degreesRotate: CGFloat = scrollOffset.y * (CGFloat.pi / 180)
rotationFunc(inIndexPath: indexPth , someAngle: degreesRotate)
}
}
我得到的输出是这样的:
https://media.giphy.com/media/WTuteL5oD3HmEk4kjR/giphy.gif
非常感谢您的宝贵时间和帮助!谢谢!如果我遗漏了什么,请告诉我!
试试这个,对所有单元格执行此操作:
for eachIndexPath in tableViewz.indexPathsForVisibleRows {
// do your rotation stuff here
}