2016-10-13 5 views
0

UIPickerView의 높이 제한을 애니메이션화합니다. 보기는 여전히 1 개 행을 보여주는 작은 높이로 점프 한 후 0UIPickerView 높이 제약 애니메이션 점프

UIView.animate(withDuration: 0.5, animations: { 
     self.timePickerHeightConstraint.constant = self.pickerIsClosed ? 216 : 0 
     self.view.layoutIfNeeded() 
    }) { compilation in 
     self.pickerIsClosed = !self.pickerIsClosed 
    } 

모든 제안을 높이까지 애니메이션? Thanka는

답변

1

당신은

self.timePickerHeightConstraint.constant = self.pickerIsClosed ? 216 : 0 

UIView.animate(withDuration: 0.5, animations: { 
    self.view.layoutIfNeeded() 
}) { compilation in 
    self.pickerIsClosed = !self.pickerIsClosed 
} 

는 또한 자동 레이아웃은 0 점으로 높이를 설정하는 것을 허용하지 않습니다 당신이 상부 및 하부 제약 조건을 설정하지 있는지 확인 애니메이션 블록 외부의 제약을 상수 값을 변경해야합니다. 이 같은

+0

고맙지 만 같은 문제가 있습니다. – ilan

+0

PickerView에 대해 설정된 제약 조건은 무엇입니까? –

+0

꼬리 끌기, 선행, 높이, 위쪽, 아래쪽 – ilan

1

시도 뭔가,

func showPickerView(_ animated: Bool) { 
    weak var weakSelf = self 
    UIView.animate(withDuration: (animated ? kPickerView_AppearanceAnimationDuration : 0.0), delay: (animated ? kPickerView_AppearanceAnimationDelay : 0.0), options: (animations as! UIViewAnimationOptionCurveEaseInOut), {() -> Void in 
     weakSelf!.pickerViewContainerView.transform = CGAffineTransform(translationX: 0, y: 0) 
    }, completion: {(finished: Bool) -> Void in 
     weakSelf!.view.layoutIfNeeded() 
    }) 
} 

func hidePickerView(_ animated: Bool) { 
    weak var weakSelf = self 
    UIView.animate(withDuration: (animated ? kPickerView_DisappearanceAnimationDuration : 0.0), delay: (animated ? kPickerView_DisappearanceAnimationDelay : 0.0), options: (animations as! UIViewAnimationOptionCurveEaseInOut), {() -> Void in 
     weakSelf!.pickerViewContainerView.transform = CGAffineTransform(translationX: 0, y: kPickerView_Height) 
    }, completion: {(finished: Bool) -> Void in 

그것은 나를 위해 작동합니다.

0

피커 구성 요소 행의 높이입니다. == 진정한 self.pickerIsClosed 때

복귀 0 (INT : UIPickerView, rowHeightForComponent 성분 pickerView)

FUNC의 pickerView 체크.

+0

도 피커보기를 다시로드합니다. – Darshana

-1

동일한 문제가있었습니다. 그것은 UIPickerView의 높이가 실제로 잘 움직이지 않는 것처럼 보입니다. 또는 최소한 내가 원하는 방식으로 애니메이션을 적용합니다.

내가 발견 한 해결 방법은 UIPickerView를 UIView 내에 랩핑하고 UIView의 clipsToBounds를 true로 설정 한 다음 UIPickerView 대신 UIView 래퍼의 높이 제약 조건에 애니메이션을 직접 수행하는 것이 었습니다. 한가지 주목할 점은 UIPicker 뷰의 높이가 래퍼 뷰의 높이와 독립적으로 제한되어야한다는 것입니다. 그렇지 않으면 래퍼없이 동일한 방식으로 반응 할 것이기 때문입니다.