Ich versuche [UIView animationWithDuration]
Methode zu verwenden, um die UIView mit den Einschränkungen zu animieren.iOS: Maurerarbeit + UIView Animation
Ich bin ziemlich vertraut mit Animation mit UIView.frame, die ziemlich geradlinig ist.
in der Init-Methode füge ich diese Subviews
-(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;
}
Und wie das Dokument auf dem Mauerwerk, die Einschränkungen in den gezeigten
-(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];
}
Und in der Show-Methode gesetzt werden
-(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*/
}];
}
Sicher, es ist die Antwort. Aber ich muss [UIView layoutIfNeeded] aufrufen, bevor ich den Constraint-Wert ändere, um die Startposition der Animation zu übernehmen. – Mix
Cool, aber ich denke nicht, dass dies der Fall ist, updateViewContraints wird während des View-Lebenszyklus aufgerufen und da der Anfangswert von 'topValue' gesetzt ist, sollte er am richtigen Ort beginnen, musst du ihn explizit aufrufen, um ihn zu bekommen Arbeit? – JingJingTao