2016-10-13 11 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 PTSに高さを設定することはできませんと、あなたがトップとボトムの制約を設定していないことを確認し、アニメーションブロックの外側で制約に一定の値を変更する必要があります。

+0

ありがとうございますが、同じ問題です。 – ilan

+0

PickerViewに設定した制約はありますか? –

+0

trailing、leading、height、top、bottom – 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

ピッカーコンポーネントの行の高さは何ですか。

戻り0真== self.pickerIsClosed

FUNCのpickerView(:UIPickerView、rowHeightForComponent成分のInt pickerView)でチェック。

+0

また、アニメーションブロックの完了時にピッカーのビューをリロードします。 – Darshana

-1

私は同じ問題を抱えていました。それは、UIPickerViewの高さが本当にうまくアニメートしないか、少なくとも私が望むようにアニメートするように見えます。

回避策は、UIPickerViewをUIView内にラップし、UIViewのclipsToBoundsをtrueに設定してからUIPickerViewの代わりにUIViewラッパーの高さ制約にアニメーションを実行することでした。注目すべきは、UIPickerビューの高さは、ラッパービューの高さとは無関係に制約されなければならないということです。

関連する問題