0
[UIView animationWithDuration]
メソッドを使用して、UIViewに制約を適用してアニメーション化しようとしています。iOS:Masonry + UIViewアニメーション
私はUIView.frameを使ったアニメーションにかなり精通していますが、これはかなり単純です。
私はそれらのサブビュー-(instancetype)init
{
if (self = [super init]) {
[self addSubview:self.bg_view];
[self.bg_view addSubview:self.content];
[self.bg_view addSubview:self.titleView];
[self.bg_view addSubview:self.reward];
}
return self;
}
と石積みの上に示された文書は、制約が
-(void)updateConstraints
{
[self makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo([UIApplication sharedApplication].keyWindow);
}];
[self.bg_view makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.titleView makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.bg_view.centerX);
make.top.equalTo(self.bg_view.top).with.offset(150);
}];
[self.content makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(self.bg_view).with.offset(-k_Margin*2);
make.bottom.equalTo(self.reward.top).with.offset(-20);
make.centerX.equalTo(self.bg_view);
make.top.equalTo(self.titleView.bottom).with.offset(20);
}];
[self.reward makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.bg_view.centerX);
make.top.equalTo(self.content.bottom).with.offset(20);
make.bottom.equalTo(self.bg_view.bottom).with.offset(-40);
}];
[super updateConstraints];
}
そしてショー方法で
-(void)show
{
[[UIApplication sharedApplication].keyWindow addSubview:self];
[self setNeedsUpdateConstraints];
[UIView animateWithDuration:5.0f animations:^{
/* I have tried variety ways to get the uiview come into the
screen from the top*/
}];
}
に設定されているように追加initメソッドで
確かに答えです。しかし、制約値を変更してアニメーションの開始位置を適用する前に、[UIView layoutIfNeeded]を呼び出す必要があります。 – Mix
しかし、私はそれが当てはまるとは思わないが、ビューのライフサイクル中にupdateViewContraintsが呼び出され、 'topValue'の初期値が設定されているため、正しい場所で開始する必要があります。作業? – JingJingTao