แบบเคลื่อนไหวการไล่ระดับสีในมุมมองของเซลล์ที่เลือก

0

คำถาม

ฉันกำลังมองต้องดำเนินการเคลื่อนไหวไปที่การไล่ระดับสีมุมมอง

มีขั้นตอนให้ความช่วยเหลือในเรื่องนั้น? ตอนนี้ผมมีทุกสิ่งทุกอย่างพร้อมและเป็นคลื่นเสียงบอกความเบื้องหลังยึดติดกับห้องขังซึ่งแสดงบส่วนที่เลือกและซ่อนตอนที่ไม่ใช่ส่วนที่เลือก. คนส่วนที่ยากคือการเคลื่อนไหวทำงานกับที่ฉันต้องการการช่วยเหลือนะ

gradient interface-builder ios swift
2021-11-24 01:15:16
1

คำตอบที่ดีที่สุด

0

คุณสามารถลองวิธีการ ->แสดง Controller

class VC2: UIViewController {

// MARK:- IBOutlets
@IBOutlet weak var tblSample: UITableView!

// MARK:- Private Variables
private var SelectedCell: Int?

// MARK:- View Lifecycle
override func viewDidLoad() {
    super.viewDidLoad()
    initialConfig()
}

// MARK:- Initial Config
private func initialConfig() {
    tblSample.delegate = self
    tblSample.dataSource = self
    
    } 
}

//โต๊ะมุมมวแทน

extension VC2: UITableViewDelegate {

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 50
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    SelectedCell = indexPath.row
    tblSample.reloadData()
    }
}

//โต๊ะแหล่งข้อมูล

extension VC2: UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 10
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.textLabel?.text = "\(indexPath.row)"
    cell.selectionStyle = .none
    if SelectedCell == indexPath.row {
        DispatchQueue.main.async {
            UIView.animate(withDuration: 1,delay: 0.5, options: .curveEaseIn) {
                cell.contentView.applyGradient(colours: [.white,.blue])
            }
        }
    }
    return cell
   }
}

//มุมมองส่วนขยายสำหรับปรับใช้และลบการไล่ระดับสี

extension UIView {

@discardableResult
func applyGradient(colours: [UIColor]) -> CAGradientLayer {
    return self.applyGradient(colours: colours, locations: nil)
}

@discardableResult
func applyGradient(colours: [UIColor], locations: [NSNumber]?) -> CAGradientLayer {
    let gradient: CAGradientLayer = CAGradientLayer()
    gradient.frame = self.bounds
    gradient.colors = colours.map { $0.cgColor }
    gradient.locations = locations
    self.layer.insertSublayer(gradient, at: 0)
    return gradient
}

func removeGradient() {
    for lay in self.layer.sublayers ?? [] {
        if lay is CAGradientLayer {
            lay.removeFromSuperlayer()
        }
    }
  }
}
2021-11-24 05:46:27

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................