Dim*_*lov 3 iphone objective-c uiviewcontroller uiview ios
我有UIViewController,这些UIViewController中有一些动画.UIView在这个UIViewController上的动画具有不同的开始和结束位置.我也有segue,它会将新的UIViewController推送到场景中.一切正常,但如果我回到我的第一个UIViewController,我的UIVIew的位置会改变到开始位置.
我怎样才能解决这个问题?
- (void)viewDidLoad
{
[super viewDidLoad];
[UIView animateWithDuration:0.3 animations:^{
self.myView.center = CGPointMake(self.myView.center.x,self.ahotherView.center.y);
}completion:^(BOOL complete){
}];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.myView.center = CGPointMake(self.myView.center.x, self.ahotherView.center.y);
}
Run Code Online (Sandbox Code Playgroud)
Autolayout导致它返回到开始位置.您可以将其关闭或编写一些代码来覆盖约束.
您必须首先在Storyboard中添加约束,这本身就是一个完全不同的问题.我建议做一些研究.一旦你添加了适当的约束并IBOutlet为它们创建了s,你将改变约束常量的值,然后[self.myView layoutIfNeeded]在动画块内调用.而不是改变center财产.可能看起来像这样:
//update constraint values
self.topConstraint.constant = 70;
self.bottomConstraint.constant = 20;
//animate
[UIView animateWithDuration:0.5f animations:^{
[self.myView layoutIfNeeded];
} completion:^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
794 次 |
| 最近记录: |