【发布时间】:2013-11-11 21:09:50
【问题描述】:
我有一个 UIView,当父视图控制器出现在屏幕上时,我正试图向上移动一点。我一直在阅读这篇文章,我看到的大多数人似乎都在说使用 viewDidAppear 方法对布局进行任何视觉调整。我已经尝试过了,它似乎不起作用。什么都没有发生,然后我 nslog 了 origin.y 我得到了 -47,000,然后我可能假设某些东西还没有初始化。这是我尝试过的。
- (void) viewDidAppear:(BOOL)animated
{
// set the save view y postion
saveData.center = CGPointMake( 0.0f, 0.5f );
NSLog(@"This is the y %f", saveData.frame.origin.y);
NSLog(@"This is the center points on load %@", NSStringFromCGPoint(optionalData.center));
}
但是如果我在 viewDidLoad 方法中添加一个延迟的方法调用这样的事情:
[self performSelector:@selector(moveSaveView) withObject:nil afterDelay:0.7f];
有了这个,就可以了
- (void) moveSaveView
{
// set the save buttons y postion
[UIView animateWithDuration:0.5 delay:0.0 options:0 animations:^{
// Animate the alpha value of your imageView from 1.0 to 0.0 here
optionalData.alpha = 0.0f;
} completion:^(BOOL finished) {
// Once the animation is completed and the alpha has gone to 0.0, hide the view for good
optionalData.hidden = YES;
}];
// move the save button up
[UIView animateWithDuration:0.5
animations:^{saveData.center = CGPointMake( 160.0f, 280.5f );}];
saveData.center = CGPointMake( 160.0f, 280.5f );
}
这也是我使用自动布局的问题吗?我只是希望我的视图从我需要的地方开始,而不是使用一些延迟调用来实现它。
编辑: 所以我试了一下,想出了这个来尝试移动我的 UIView:
- (void) viewDidAppear:(BOOL)animated
{
NSLog(@"this is the constraing %f", saveData.saveButtomConstraint.constant); // gives me 93 which is here its at.
saveData.saveButtomConstraint.constant = 32;
[saveData setNeedsUpdateConstraints];
[saveData layoutIfNeeded];
NSLog(@"this is the constraing %f", saveData.saveButtomConstraint.constant); // gives me 32 which is here its at.
}
问题是视图永远不会在屏幕上移动。我错过了什么?当它与同一个问题相关时,也可以像这样发布和编辑吗?我仍在努力掌握这个表格。
【问题讨论】: