2017-05-02 3 views
0

애니메이션이 내 UITableView에 추가되었지만 처음로드 할 때 설정 한 제약 조건에 맞지 않습니다. 그들은 세포의 높이와 너비가 다소 압착되었습니다.테이블 셀 제약 조건이 제대로로드되지 않습니다.

애니메이션은 UITableView, willDisplay cell의 대리자 메서드에 몸처럼 보이는 다음 superView로 설정되어 UITableView에 대한

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
     cell.alpha = 0 
     cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1) 

     cell.layoutIfNeeded() 
     UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: { 
      cell.alpha = 0.5 
      cell.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1) 
      cell.layoutIfNeeded() 
     },completion: { finished in 
      UIView.animate(withDuration: 0.1, animations: { 
       cell.alpha = 1 
       cell.layer.transform = CATransform3DMakeScale(1, 1, 1) 
       cell.layoutIfNeeded() 
      }) 
     }) 
    } 

내 제약, 그들은 그것의 전체 공간 취

private func setupConstraints() { 
     let topVehiclesTableViewConstraint = vehiclesTableView.topAnchor.constraint(equalTo: view.topAnchor) 
     let bottomVehiclesTableViewConstraint = vehiclesTableView.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor) 
     let leadingVehiclesTableViewConstraint = vehiclesTableView.leadingAnchor.constraint(equalTo: view.leadingAnchor) 
     let trailingVehiclesTableViewConstraint = vehiclesTableView.trailingAnchor.constraint(equalTo: view.trailingAnchor) 

     view.addConstraints([topVehiclesTableViewConstraint, bottomVehiclesTableViewConstraint, leadingVehiclesTableViewConstraint, trailingVehiclesTableViewConstraint]) 
    } 
setupViews() 호출된다 :

있어서 setupConstraints() 방법은 내부 호출 사용자 정의 셀

override func viewDidLoad() { 
     super.viewDidLoad() 
     setupViews() 
} 

필요한 기능 :

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
     super.init(style: style, reuseIdentifier: reuseIdentifier) 
     setupViews() 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 

    override func awakeFromNib() { 
     super.awakeFromNib() 
    } 

    override func setSelected(_ selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 
    } 

편집

내가 볼 셀 애니메이션을 가지고 또한 많은 시간을로드. 그래서 3-4 개의 세포가 있다면, 애니메이션은 3-4 번 반복 될 것입니다. 그건 내가 원하는 것이 아니야.

이 버그를 어떻게 해결할 수 있습니까? 사전에

Shows how it is now, and how it should be

감사합니다!

+0

awakeFromNib에서 setupViews() 메서드를 호출 해 보았습니까? –

+0

@ShalvaAvanashvili 셀 물건들은 셀 등록 후에'tableView'를 가진'View Controller'의'setupViews()'에서 호출됩니다. cellForRow의 – yerpy

+0

은 reuseIdentifier 또는 reuseIdentifier를 사용하여 셀을 dequeing하고 있습니까? IndexPath? 두 가지 방법이 있습니다 – SeanLintern88

답변

0

이 시도 :

willDisplay에서 위임 방법은

cell.layoutIfNeeded() 

줄 끝에서

cell.layer.removeAllAnimations() 

를 추가합니다.

+0

아무 것도 변경하지 않습니다. – yerpy

+0

내 대답이 업데이트되었습니다. view.layer.removeAllAnimations() 대신 cell.layer.removeAllAnimations()를 사용해보십시오. –

+0

같은 결과; \. – yerpy

관련 문제