2016-07-05 6 views
0

위젯을 사용합니다. 애니메이션으로 셀 높이를 변경해야합니다. "더보기"를 클릭하면 추가 컨트롤로 이동하십시오. enter image description hereUITableView 셀 높이 애니메이션

는이 코드

 tableView.beginUpdates() 
     showModes(alpha: 1, duration: 0.2, delay: 0.1) 
     tableView.endUpdates() 

func showModes(alpha: CGFloat, duration: CGFloat, delay: CGFloat) { 
    if tableView.numberOfRows(inSection: 0) != 0 { 
     for i in 0...tableView.numberOfRows(inSection: 0)-1 { 
      let indexPath = IndexPath(row: i, section: 0) 
      if let cell = tableView.cellForRow(at: indexPath) as? WidgetCell { 
       UIView.animate(withDuration: TimeInterval(duration), delay: TimeInterval(delay) ,animations: { 
        if alpha == 0 { 
         cell.favoriteConstraint.constant = -45 
        } else { 
         cell.favoriteConstraint.constant = 10 
        } 
        cell.favoriteMode.alpha = alpha 
        self.tableView.layoutIfNeeded() 
       }) 

      } 
     } 
    } 
} 

을 썼다 그러나이 원활하게 작동하지 않습니다. 그것은 극적으로 위아래로 트위스트. 예를 들어 Apple의 날씨 위젯과 같이이 기능을 원활하게 작동 시키려면 어떻게해야합니까?

답변

0

코드의 일부만 게시했기 때문에 어떤 것이 문제인지 인식 할 수 없습니다. 하지만 할 수있는 몇 가지 수표를 제안 할 수 있습니다

  1. UITableView에 대한 자체 크기 조정 셀을 설정 했습니까? AtableView.rowHeight = UITableViewAutomaticDimension;
  2. 추가 한 제약 (favoriteConstraint)에게 한 세포의있는 contentView

또한 제약 조건을 애니메이션하는 것은 당신이 애니메이션 폐쇄 내부를 변경할 필요가 없습니다 변경 될 때.

cell.favoriteConstraint.constant = newValue 
    UIView.animateWithDuration(0.3) { 
    cell.contentView.layoutIfNeeded() 
} 

은 또한 당신이 당신의 메서드 호출을 래핑 할 필요가 없습니다처럼

표준 코드 보인다. 이 확인되어야합니다

showModes(alpha: 1, duration: 0.2, delay: 0.1) 
tableView.beginUpdates()  
tableView.endUpdates() 
+0

예, 그것은 모두의 viewDidLoad() { super.viewDidLoad() ledControllers = readLED() self.tableView.estimatedRowHeight = 300 self.tableView.rowHeight = FUNC 재정의를 추가 UITableViewAutomaticDimension } 비디오를 명확하게 녹음했습니다. 첫 번째 셀이 확장되고 애니메이션 만 시작됩니다. 날씨 위젯과 비슷했으면 좋겠다. https://youtu.be/f4D7NnoyWrQ P. Судя по нику вы говорите по русски? – MacSergey